Commit 53263cecd681f27f5e5473a66e41649584a5fc3a

Authored by Jarrett Jordaan
2 parents 8f018fb7 3db1998b

Merge branch 'edge' of git@github.com:ktgit/knowledgetree into edge

config/dmsDefaults.php
@@ -47,7 +47,7 @@ if (defined('DMS_DEFAULTS_INCLUDED')) @@ -47,7 +47,7 @@ if (defined('DMS_DEFAULTS_INCLUDED'))
47 } 47 }
48 48
49 define('DMS_DEFAULTS_INCLUDED',1); 49 define('DMS_DEFAULTS_INCLUDED',1);
50 -define('LATEST_WEBSERVICE_VERSION',2); 50 +define('LATEST_WEBSERVICE_VERSION',3);
51 51
52 52
53 if (function_exists('apd_set_pprof_trace')) { 53 if (function_exists('apd_set_pprof_trace')) {
ktapi/KTAPIConstants.inc.php
@@ -5,32 +5,32 @@ @@ -5,32 +5,32 @@
5 * KnowledgeTree Community Edition 5 * KnowledgeTree Community Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
7 * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc. 7 * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc.
8 - *  
9 - * 8 + *
  9 + *
10 * This program is free software; you can redistribute it and/or modify it under 10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License version 3 as published by the 11 * the terms of the GNU General Public License version 3 as published by the
12 * Free Software Foundation. 12 * Free Software Foundation.
13 - * 13 + *
14 * This program is distributed in the hope that it will be useful, but WITHOUT 14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * details. 17 * details.
18 - * 18 + *
19 * You should have received a copy of the GNU General Public License 19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 - *  
22 - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, 21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23 * California 94120-7775, or email info@knowledgetree.com. 23 * California 94120-7775, or email info@knowledgetree.com.
24 - * 24 + *
25 * The interactive user interfaces in modified source and object code versions 25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under 26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU General Public License version 3. 27 * Section 5 of the GNU General Public License version 3.
28 - * 28 + *
29 * In accordance with Section 7(b) of the GNU General Public License version 3, 29 * In accordance with Section 7(b) of the GNU General Public License version 3,
30 * these Appropriate Legal Notices must retain the display of the "Powered by 30 * these Appropriate Legal Notices must retain the display of the "Powered by
31 - * KnowledgeTree" logo and retain the original copyright notice. If the display of the 31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices 32 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33 - * must display the words "Powered by KnowledgeTree" and retain the original 33 + * must display the words "Powered by KnowledgeTree" and retain the original
34 * copyright notice. 34 * copyright notice.
35 * Contributor( s): ______________________________________ 35 * Contributor( s): ______________________________________
36 */ 36 */
@@ -53,6 +53,7 @@ define(&#39;KTAPI_ERROR_SESSION_INVALID&#39;, &#39;The session could not be resolved.&#39;); @@ -53,6 +53,7 @@ define(&#39;KTAPI_ERROR_SESSION_INVALID&#39;, &#39;The session could not be resolved.&#39;);
53 define('KTAPI_ERROR_PERMISSION_INVALID', 'The permission could not be resolved.'); 53 define('KTAPI_ERROR_PERMISSION_INVALID', 'The permission could not be resolved.');
54 define('KTAPI_ERROR_FOLDER_INVALID', 'The folder could not be resolved.'); 54 define('KTAPI_ERROR_FOLDER_INVALID', 'The folder could not be resolved.');
55 define('KTAPI_ERROR_DOCUMENT_INVALID', 'The document could not be resolved.'); 55 define('KTAPI_ERROR_DOCUMENT_INVALID', 'The document could not be resolved.');
  56 +define('KTAPI_ERROR_VERSION_INVALID', 'The document version could not be resolved.');
56 define('KTAPI_ERROR_USER_INVALID', 'The user could not be resolved.'); 57 define('KTAPI_ERROR_USER_INVALID', 'The user could not be resolved.');
57 define('KTAPI_ERROR_KTAPI_INVALID', 'The ktapi could not be resolved.'); 58 define('KTAPI_ERROR_KTAPI_INVALID', 'The ktapi could not be resolved.');
58 define('KTAPI_ERROR_INSUFFICIENT_PERMISSIONS', 'The user does not have sufficient permissions to access the resource.'); 59 define('KTAPI_ERROR_INSUFFICIENT_PERMISSIONS', 'The user does not have sufficient permissions to access the resource.');
ktapi/KTAPIDocument.inc.php
@@ -91,16 +91,17 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -91,16 +91,17 @@ class KTAPI_Document extends KTAPI_FolderItem
91 } 91 }
92 92
93 /** 93 /**
94 - * This is used to get a document based on document id. 94 + * This is used to get a document based on document id. Or a version of the document based on the metadata version id
95 * 95 *
96 * @author KnowledgeTree Team 96 * @author KnowledgeTree Team
97 * @static 97 * @static
98 * @access public 98 * @access public
99 * @param KTAPI $ktapi The ktapi object 99 * @param KTAPI $ktapi The ktapi object
100 * @param int $documentid The document id 100 * @param int $documentid The document id
  101 + * @param int $iMetadataVersionId Optional. The metadata version id
101 * @return KTAPI_Document The document object 102 * @return KTAPI_Document The document object
102 */ 103 */
103 - function &get(&$ktapi, $documentid) 104 + function &get(&$ktapi, $documentid, $iMetadataVersionId = null)
104 { 105 {
105 assert(!is_null($ktapi)); 106 assert(!is_null($ktapi));
106 assert(is_a($ktapi, 'KTAPI')); 107 assert(is_a($ktapi, 'KTAPI'));
@@ -108,7 +109,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -108,7 +109,7 @@ class KTAPI_Document extends KTAPI_FolderItem
108 109
109 $documentid += 0; 110 $documentid += 0;
110 111
111 - $document = &Document::get($documentid); 112 + $document = &Document::get($documentid, $iMetadataVersionId);
112 if (is_null($document) || PEAR::isError($document)) 113 if (is_null($document) || PEAR::isError($document))
113 { 114 {
114 return new KTAPI_Error(KTAPI_ERROR_DOCUMENT_INVALID,$document ); 115 return new KTAPI_Error(KTAPI_ERROR_DOCUMENT_INVALID,$document );
@@ -137,6 +138,30 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -137,6 +138,30 @@ class KTAPI_Document extends KTAPI_FolderItem
137 } 138 }
138 139
139 /** 140 /**
  141 + * This is used to get a document based on the document id and the metadata version
  142 + *
  143 + * @author KnowledgeTree Team
  144 + * @static
  145 + * @access public
  146 + * @param KTAPI $ktapi The ktapi object
  147 + * @param int $documentid The document id
  148 + * @param int $metadataVersion The metadata version (0,1,2)
  149 + * @return KTAPI_Document The document object
  150 + */
  151 + function &get_by_metadata_version(&$ktapi, $documentid, $metadataVersion)
  152 + {
  153 + // get the metadata version id
  154 + $iMetadataVersionId = Document::getMetadataVersionIdFromVersion($documentid, $metadataVersion);
  155 + if (is_null($iMetadataVersionId) || PEAR::isError($iMetadataVersionId))
  156 + {
  157 + return new KTAPI_Error(KTAPI_ERROR_VERSION_INVALID, $iMetadataVersionId );
  158 + }
  159 +
  160 + // get the KTAPI_Document object
  161 + return self::get($ktapi, $documentid, $iMetadataVersionId);
  162 + }
  163 +
  164 + /**
140 * Checks if a document has been deleted 165 * Checks if a document has been deleted
141 * 166 *
142 * @author KnowledgeTree Team 167 * @author KnowledgeTree Team
@@ -2137,13 +2162,14 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -2137,13 +2162,14 @@ class KTAPI_Document extends KTAPI_FolderItem
2137 * @author KnowledgeTree Team 2162 * @author KnowledgeTree Team
2138 * @access public 2163 * @access public
2139 */ 2164 */
2140 - function download() 2165 + function download($version = null)
2141 { 2166 {
2142 $storage =& KTStorageManagerUtil::getSingleton(); 2167 $storage =& KTStorageManagerUtil::getSingleton();
2143 $options = array(); 2168 $options = array();
2144 2169
  2170 + $comment = (!is_null($version)) ? 'Document version '.$version.' downloaded' : 'Document downloaded';
2145 $oDocumentTransaction = new DocumentTransaction($this->document, 'Document downloaded', 'ktcore.transactions.download', $aOptions); 2171 $oDocumentTransaction = new DocumentTransaction($this->document, 'Document downloaded', 'ktcore.transactions.download', $aOptions);
2146 - $oDocumentTransaction->create(); 2172 + return $oDocumentTransaction->create();
2147 } 2173 }
2148 2174
2149 /** 2175 /**
@@ -2241,6 +2267,17 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -2241,6 +2267,17 @@ class KTAPI_Document extends KTAPI_FolderItem
2241 } 2267 }
2242 2268
2243 /** 2269 /**
  2270 + * Get the content version id using the document (content) version - major/minor version
  2271 + *
  2272 + * @param string $version
  2273 + * @return int
  2274 + */
  2275 + function get_content_version_id_from_version($version)
  2276 + {
  2277 + return $this->document->getContentVersionIdFromVersion($version);
  2278 + }
  2279 +
  2280 + /**
2244 * This expunges a document from the system. 2281 * This expunges a document from the system.
2245 * 2282 *
2246 * <code> 2283 * <code>
ktapi/ktapi.inc.php
@@ -870,6 +870,22 @@ class KTAPI @@ -870,6 +870,22 @@ class KTAPI
870 } 870 }
871 871
872 /** 872 /**
  873 + * This returns a refererence to a document based on document id.
  874 + *
  875 + * @author KnowledgeTree Team
  876 + * @access public
  877 + * @param integer $documentid The document id
  878 + * @param integer $metadataVersion The metadata version of the document (not the id)
  879 + * @return object $document The KTAPI_Document object
  880 + */
  881 + public function &get_document_by_metadata_version($documentid, $metadataVersion)
  882 + {
  883 + // Get the document using the metadata version
  884 + $document = KTAPI_Document::get_by_metadata_version($this, $documentid, $metadataVersion);
  885 + return $document;
  886 + }
  887 +
  888 + /**
873 * This returns a document type id based on the name or an error object. 889 * This returns a document type id based on the name or an error object.
874 * 890 *
875 * @author KnowledgeTree Team 891 * @author KnowledgeTree Team
ktwebservice/KTDownloadManager.inc.php
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 * KnowledgeTree Community Edition 9 * KnowledgeTree Community Edition
10 * Document Management Made Simple 10 * Document Management Made Simple
11 * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc. 11 * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc.
12 - * 12 + *
13 * 13 *
14 * This program is free software; you can redistribute it and/or modify it under 14 * This program is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU General Public License version 3 as published by the 15 * the terms of the GNU General Public License version 3 as published by the
@@ -76,44 +76,41 @@ class KTDownloadManager @@ -76,44 +76,41 @@ class KTDownloadManager
76 { 76 {
77 $this->session = $session; 77 $this->session = $session;
78 } 78 }
79 - 79 +
80 /** 80 /**
81 * This returns 81 * This returns
82 * 82 *
83 * @access public 83 * @access public
84 * @param KTAPI_Document $document 84 * @param KTAPI_Document $document
  85 + * @param int $content_version_id Optional. The id of the requested content version
85 * @return string 86 * @return string
86 */ 87 */
87 - function allow_download($document, $content_version = null, $multipart = false) { 88 + function allow_download($document, $content_version_id = null, $multipart = false) {
88 assert ( ! is_null ( $document ) ); 89 assert ( ! is_null ( $document ) );
89 -  
90 - $content_version = 0; 90 +
91 $filesize = 0; 91 $filesize = 0;
92 - 92 +
93 if ($document instanceof KTAPI_Document) { 93 if ($document instanceof KTAPI_Document) {
94 $doc_id = $document->documentid; 94 $doc_id = $document->documentid;
95 - $content_version = $document->document->getContentVersionId (); 95 + //$content_version_id = (is_numeric($content_version_id)) ? $content_version_id : $document->document->getContentVersionId();
96 $filesize = $document->document->getFileSize (); 96 $filesize = $document->document->getFileSize ();
97 } else if ($document instanceof Document || $document instanceof DocumentProxy) { 97 } else if ($document instanceof Document || $document instanceof DocumentProxy) {
98 $doc_id = $document->getId (); 98 $doc_id = $document->getId ();
99 - $content_version = $document->getContentVersionId (); 99 + //$content_version_id = (is_numeric($content_version_id)) ? $content_version_id : $document->getContentVersionId();
100 $filesize = $document->getFileSize (); 100 $filesize = $document->getFileSize ();
101 } else if (is_numeric ( $document )) { 101 } else if (is_numeric ( $document )) {
102 $doc_id = $document; 102 $doc_id = $document;
103 } else 103 } else
104 die ( 'gracefully' ); 104 die ( 'gracefully' );
105 -  
106 - //assert(is_a($document, 'KTAPI_Document'));  
107 -  
108 -  
109 - $hash = sha1 ( "$doc_id $this->session $this->random" );  
110 -  
111 - $id = DBUtil::autoInsert ( 'download_files', array ('document_id' => $doc_id, 'session' => $this->session, 'download_date' => date ( 'Y-m-d H:i:s' ), 'content_version' => $content_version, 'filesize' => $filesize, 'hash' => $hash ), array ('noid' => true ) );  
112 -  
113 - return $multipart?$this->build_multipart_url( $hash, $doc_id ):$this->build_url ( $hash, $doc_id ); 105 +
  106 + $hash = sha1 ( "$doc_id $content_version_id $this->session $this->random" );
  107 +
  108 + $id = DBUtil::autoInsert ( 'download_files', array ('document_id' => $doc_id, 'session' => $this->session, 'download_date' => date ( 'Y-m-d H:i:s' ), 'content_version' => $content_version_id, 'filesize' => $filesize, 'hash' => $hash ), array ('noid' => true ) );
  109 +
  110 + return $multipart ? $this->build_multipart_url( $hash, $doc_id ) : $this->build_url ( $hash, $doc_id );
114 } 111 }
115 -  
116 - 112 +
  113 +
117 /** 114 /**
118 * This returns the url used to download a document. 115 * This returns the url used to download a document.
119 * 116 *
@@ -125,21 +122,24 @@ class KTDownloadManager @@ -125,21 +122,24 @@ class KTDownloadManager
125 function build_url($hash, $documentid) { 122 function build_url($hash, $documentid) {
126 return $this->download_url . "?code=$hash&d=$documentid&u=$this->session"; 123 return $this->download_url . "?code=$hash&d=$documentid&u=$this->session";
127 } 124 }
128 - 125 +
129 function build_multipart_url($hash, $documentId) { 126 function build_multipart_url($hash, $documentId) {
130 -// return '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@';  
131 return $this->multipart_download_url . "?code=$hash&d=$documentId&u=$this->session"; 127 return $this->multipart_download_url . "?code=$hash&d=$documentId&u=$this->session";
132 } 128 }
133 129
134 -  
135 /** 130 /**
136 * This starts a download. 131 * This starts a download.
137 * 132 *
138 * @access public 133 * @access public
  134 + *
  135 + * @param int $document_id
  136 + * @param string $hash
  137 + * @param string $apptype
  138 + * @return mixed
139 */ 139 */
140 - function download($document_id, $hash, $version = null, $apptype = 'ws') 140 + function download($document_id, $hash, $apptype = 'ws')
141 { 141 {
142 - $sql = "SELECT 1 FROM download_files WHERE hash=? AND session=? AND document_id=?"; 142 + $sql = "SELECT content_version FROM download_files WHERE hash=? AND session=? AND document_id=?";
143 $rows = DBUtil::getResultArray(array($sql, array($hash, $this->session, $document_id))); 143 $rows = DBUtil::getResultArray(array($sql, array($hash, $this->session, $document_id)));
144 if (PEAR::isError($rows)) 144 if (PEAR::isError($rows))
145 { 145 {
@@ -151,11 +151,14 @@ class KTDownloadManager @@ -151,11 +151,14 @@ class KTDownloadManager
151 return new PEAR_Error('Invalid session.'); 151 return new PEAR_Error('Invalid session.');
152 } 152 }
153 153
  154 + // Get the content version id
  155 + $content_version_id = $rows[0]['content_version'];
  156 +
154 // If document is being downloaded by an external user bypass the session checking 157 // If document is being downloaded by an external user bypass the session checking
155 $check = strstr($this->session, 'ktext_'.$document_id); 158 $check = strstr($this->session, 'ktext_'.$document_id);
156 if($check == 0 && $check !== false){ 159 if($check == 0 && $check !== false){
157 // Use external download function 160 // Use external download function
158 - return $this->download_ext($document_id, $hash, $version = null); 161 + return $this->download_ext($document_id, $hash, $content_version_id);
159 } 162 }
160 163
161 $storage =& KTStorageManagerUtil::getSingleton(); 164 $storage =& KTStorageManagerUtil::getSingleton();
@@ -173,11 +176,9 @@ class KTDownloadManager @@ -173,11 +176,9 @@ class KTDownloadManager
173 return $document; 176 return $document;
174 } 177 }
175 178
176 - if (!empty($version)) 179 + if (!empty($content_version_id))
177 { 180 {
178 - $version = KTDocumentContentVersion::get($version);  
179 -  
180 - $res = $storage->downloadVersion($document->document, $version); 181 + $res = $storage->downloadVersion($document->document, $content_version_id);
181 } 182 }
182 else 183 else
183 { 184 {
@@ -193,8 +194,8 @@ class KTDownloadManager @@ -193,8 +194,8 @@ class KTDownloadManager
193 194
194 return true; 195 return true;
195 } 196 }
196 -  
197 - function download_ext($document_id, $hash, $version = null) 197 +
  198 + function download_ext($document_id, $hash, $content_version_id = null)
198 { 199 {
199 $storage =& KTStorageManagerUtil::getSingleton(); 200 $storage =& KTStorageManagerUtil::getSingleton();
200 $document = Document::get($document_id); 201 $document = Document::get($document_id);
@@ -203,11 +204,9 @@ class KTDownloadManager @@ -203,11 +204,9 @@ class KTDownloadManager
203 return $document; 204 return $document;
204 } 205 }
205 206
206 - if (!empty($version)) 207 + if (!empty($content_version_id))
207 { 208 {
208 - $version = KTDocumentContentVersion::get($version);  
209 -  
210 - $res = $storage->downloadVersion($document, $version); 209 + $res = $storage->downloadVersion($document, $content_version_id);
211 } 210 }
212 else 211 else
213 { 212 {
@@ -237,4 +236,4 @@ class KTDownloadManager @@ -237,4 +236,4 @@ class KTDownloadManager
237 DBUtil::runQuery($sql); 236 DBUtil::runQuery($sql);
238 } 237 }
239 } 238 }
240 -?> 239 -?>
  240 +?>
241 \ No newline at end of file 241 \ No newline at end of file
ktwebservice/download.php
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 * KnowledgeTree Community Edition 7 * KnowledgeTree Community Edition
8 * Document Management Made Simple 8 * Document Management Made Simple
9 * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc. 9 * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc.
10 - * 10 + *
11 * 11 *
12 * This program is free software; you can redistribute it and/or modify it under 12 * This program is free software; you can redistribute it and/or modify it under
13 * the terms of the GNU General Public License version 3 as published by the 13 * the terms of the GNU General Public License version 3 as published by the
@@ -73,7 +73,7 @@ require_once(&#39;KTDownloadManager.inc.php&#39;); @@ -73,7 +73,7 @@ require_once(&#39;KTDownloadManager.inc.php&#39;);
73 $download_manager = new KTDownloadManager(); 73 $download_manager = new KTDownloadManager();
74 $download_manager->set_session($session); 74 $download_manager->set_session($session);
75 75
76 -$response = $download_manager->download($document_id, $hash, null, $apptype); 76 +$response = $download_manager->download($document_id, $hash, $apptype);
77 if (PEAR::isError($response)) 77 if (PEAR::isError($response))
78 { 78 {
79 $msg = urlencode($response->getMessage()); 79 $msg = urlencode($response->getMessage());
ktwebservice/webservice.php
@@ -60,8 +60,6 @@ if (defined(&#39;HAS_SEARCH_FUNCTIONALITY&#39;)) @@ -60,8 +60,6 @@ if (defined(&#39;HAS_SEARCH_FUNCTIONALITY&#39;))
60 require_once(KT_DIR . '/search2/search/search.inc.php'); 60 require_once(KT_DIR . '/search2/search/search.inc.php');
61 } 61 }
62 62
63 -// TODO: allow downloading of metadata versions  
64 -// TODO: allow downloading of document versions  
65 // TODO: chunking search results 63 // TODO: chunking search results
66 // TODO: add basic permissions management - add permissions to folder based on user/groups 64 // TODO: add basic permissions management - add permissions to folder based on user/groups
67 // TODO: refactor!!! download manager, split this file into a few smaller ones, etc 65 // TODO: refactor!!! download manager, split this file into a few smaller ones, etc
@@ -72,7 +70,7 @@ if (defined(&#39;HAS_SEARCH_FUNCTIONALITY&#39;)) @@ -72,7 +70,7 @@ if (defined(&#39;HAS_SEARCH_FUNCTIONALITY&#39;))
72 // TODO: ktwsapi/php must be made compatible with v2/v3 70 // TODO: ktwsapi/php must be made compatible with v2/v3
73 // TODO: subscriptions/notifications 71 // TODO: subscriptions/notifications
74 72
75 -// NOTE: some features are not implemented yet. most expected for v3. e.g. oem_document_no, custom_document_no, download($version)., get_metadata($version) 73 +// NOTE: some features are not implemented yet. most expected for v3. e.g. oem_document_no, custom_document_no
76 74
77 // Status Codes as defined in the specification. 75 // Status Codes as defined in the specification.
78 76
@@ -97,7 +95,7 @@ define(&#39;KTWS_ERR_DB_PROBLEM&#39;, 99); @@ -97,7 +95,7 @@ define(&#39;KTWS_ERR_DB_PROBLEM&#39;, 99);
97 95
98 if (!defined('LATEST_WEBSERVICE_VERSION')) 96 if (!defined('LATEST_WEBSERVICE_VERSION'))
99 { 97 {
100 - define('LATEST_WEBSERVICE_VERSION', 2); 98 + define('LATEST_WEBSERVICE_VERSION', 3);
101 } 99 }
102 100
103 function bool2str($bool) 101 function bool2str($bool)
@@ -2944,12 +2942,13 @@ class KTWebService @@ -2944,12 +2942,13 @@ class KTWebService
2944 * 2942 *
2945 * @param string $session_id 2943 * @param string $session_id
2946 * @param int $document_id 2944 * @param int $document_id
  2945 + * @param string $version The document (content) version - "major version" . "minor version"
2947 2946
2948 * @return kt_response. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS 2947 * @return kt_response. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS
2949 */ 2948 */
2950 function download_document($session_id, $document_id, $version=null) 2949 function download_document($session_id, $document_id, $version=null)
2951 { 2950 {
2952 - $this->debug("download_document('$session_id',$document_id)"); 2951 + $this->debug("download_document('$session_id',$document_id, '$version')");
2953 2952
2954 $kt = &$this->get_ktapi($session_id ); 2953 $kt = &$this->get_ktapi($session_id );
2955 if (is_array($kt)) 2954 if (is_array($kt))
@@ -2968,11 +2967,23 @@ class KTWebService @@ -2968,11 +2967,23 @@ class KTWebService
2968 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); 2967 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
2969 } 2968 }
2970 2969
2971 - $result = $document->download(); 2970 + $content_version_id = null;
  2971 + if(!empty($version)){
  2972 + // Get the content version id for the given document version
  2973 + $content_version_id = $document->get_content_version_id_from_version($version);
  2974 + if (PEAR::isError($content_version_id))
  2975 + {
  2976 + $response['message'] = $result->getMessage();
  2977 + $this->debug("download_document - cannot get version $version - " . $result->getMessage(), $session_id);
  2978 + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2979 + }
  2980 + }
  2981 +
  2982 + $result = $document->download($version);
2972 if (PEAR::isError($result)) 2983 if (PEAR::isError($result))
2973 { 2984 {
2974 $response['message'] = $result->getMessage(); 2985 $response['message'] = $result->getMessage();
2975 - $this->debug("download_document - cannot download - " . $result->getMessage(), $session_id); 2986 + $this->debug("download_document - cannot download (version $version) - " . $result->getMessage(), $session_id);
2976 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); 2987 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
2977 } 2988 }
2978 2989
@@ -2980,7 +2991,7 @@ class KTWebService @@ -2980,7 +2991,7 @@ class KTWebService
2980 $download_manager = new KTDownloadManager(); 2991 $download_manager = new KTDownloadManager();
2981 $download_manager->set_session($session->session); 2992 $download_manager->set_session($session->session);
2982 $download_manager->cleanup(); 2993 $download_manager->cleanup();
2983 - $url = $download_manager->allow_download($document); 2994 + $url = $download_manager->allow_download($document, $content_version_id);
2984 2995
2985 $response['status_code'] = KTWS_SUCCESS; 2996 $response['status_code'] = KTWS_SUCCESS;
2986 $response['message'] = $url; 2997 $response['message'] = $url;
@@ -3016,7 +3027,19 @@ class KTWebService @@ -3016,7 +3027,19 @@ class KTWebService
3016 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); 3027 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
3017 } 3028 }
3018 3029
3019 - $result = $document->download(); 3030 + $content_version_id = null;
  3031 + if(!empty($version)){
  3032 + // Get the content version id for the given document version
  3033 + $content_version_id = $document->get_content_version_id_from_version($version);
  3034 + if (PEAR::isError($content_version_id))
  3035 + {
  3036 + $response['message'] = $result->getMessage();
  3037 + $this->debug("download_document - cannot get version $version - " . $result->getMessage(), $session_id);
  3038 + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  3039 + }
  3040 + }
  3041 +
  3042 + $result = $document->download($version);
3020 if (PEAR::isError($result)) 3043 if (PEAR::isError($result))
3021 { 3044 {
3022 $response['message'] = $result->getMessage(); 3045 $response['message'] = $result->getMessage();
@@ -3024,24 +3047,33 @@ class KTWebService @@ -3024,24 +3047,33 @@ class KTWebService
3024 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); 3047 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
3025 } 3048 }
3026 3049
3027 - $content=''; 3050 + $content = '';
  3051 + $oStorage =& KTStorageManagerUtil::getSingleton();
3028 3052
3029 - $document = $document->document; 3053 + // for a specified version
  3054 + if(is_numeric($content_version_id)){
  3055 + $filename = $oStorage->temporaryFileForVersion($content_version_id);
3030 3056
3031 - $oStorage =& KTStorageManagerUtil::getSingleton();  
3032 - $filename = $oStorage->temporaryFile($document);  
3033 -  
3034 - $fp=fopen($filename,'rb');  
3035 - if ($fp === false)  
3036 - { 3057 + if(!$filename){
3037 $response['message'] = 'The file is not in the storage system. Please contact an administrator!'; 3058 $response['message'] = 'The file is not in the storage system. Please contact an administrator!';
3038 - $this->debug("download_small_document - cannot write $filename", $session_id); 3059 + $this->debug("download_small_document - $filename cannot be found in the storage system", $session_id);
3039 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); 3060 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
3040 - }  
3041 - $content = fread($fp, filesize($filename));  
3042 - fclose($fp);  
3043 - $content = base64_encode($content); 3061 + }
  3062 + }else{
  3063 + $document = $document->document;
  3064 + $filename = $oStorage->temporaryFile($document);
  3065 + }
3044 3066
  3067 + $fp=fopen($filename,'rb');
  3068 + if ($fp === false)
  3069 + {
  3070 + $response['message'] = 'The file is not in the storage system. Please contact an administrator!';
  3071 + $this->debug("download_small_document - cannot read $filename", $session_id);
  3072 + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  3073 + }
  3074 + $content = fread($fp, filesize($filename));
  3075 + fclose($fp);
  3076 + $content = base64_encode($content);
3045 3077
3046 $response['status_code'] = KTWS_SUCCESS; 3078 $response['status_code'] = KTWS_SUCCESS;
3047 $response['message'] = $content; 3079 $response['message'] = $content;
@@ -3743,9 +3775,9 @@ class KTWebService @@ -3743,9 +3775,9 @@ class KTWebService
3743 * @param int $document_id 3775 * @param int $document_id
3744 * @return kt_metadata_response 3776 * @return kt_metadata_response
3745 */ 3777 */
3746 - function get_document_metadata($session_id,$document_id) 3778 + function get_document_metadata($session_id, $document_id, $version = null)
3747 { 3779 {
3748 - $this->debug("get_document_metadata('$session_id',$document_id)"); 3780 + $this->debug("get_document_metadata('$session_id',$document_id, $version)");
3749 3781
3750 $kt = &$this->get_ktapi($session_id ); 3782 $kt = &$this->get_ktapi($session_id );
3751 if (is_array($kt)) 3783 if (is_array($kt))
@@ -3755,7 +3787,12 @@ class KTWebService @@ -3755,7 +3787,12 @@ class KTWebService
3755 3787
3756 $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT); 3788 $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
3757 3789
3758 - $document = &$kt->get_document_by_id($document_id); 3790 + if(is_numeric($version)){
  3791 + $document = &$kt->get_document_by_metadata_version($document_id, $version);
  3792 + }else {
  3793 + $document = &$kt->get_document_by_id($document_id);
  3794 + }
  3795 +
3759 if (PEAR::isError($document)) 3796 if (PEAR::isError($document))
3760 { 3797 {
3761 $response['message'] = $document->getMessage(); 3798 $response['message'] = $document->getMessage();
lib/documentmanagement/Document.inc
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 * KnowledgeTree Community Edition 5 * KnowledgeTree Community Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
7 * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc. 7 * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc.
8 - * 8 + *
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify it under 10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License version 3 as published by the 11 * the terms of the GNU General Public License version 3 as published by the
@@ -169,7 +169,7 @@ class Document { @@ -169,7 +169,7 @@ class Document {
169 169
170 function getStoragePath() { return $this->_oDocumentContentVersion->getStoragePath(); } 170 function getStoragePath() { return $this->_oDocumentContentVersion->getStoragePath(); }
171 function setStoragePath($sNewValue) { $this->_oDocumentContentVersion->setStoragePath($sNewValue); } 171 function setStoragePath($sNewValue) { $this->_oDocumentContentVersion->setStoragePath($sNewValue); }
172 - 172 +
173 173
174 174
175 /** 175 /**
@@ -679,6 +679,50 @@ class Document { @@ -679,6 +679,50 @@ class Document {
679 } 679 }
680 // }}} 680 // }}}
681 681
  682 + // {{{ getContentVersionIdFromVersion
  683 + function getContentVersionIdFromVersion($version)
  684 + {
  685 + $aVersion = explode('.', $version);
  686 + $major = $aVersion[0];
  687 + $minor = $aVersion[1];
  688 +
  689 + $doc_id = $this->iId;
  690 +
  691 + $query = "select id from document_content_version where document_id = $doc_id and major_version = $major and minor_version = $minor";
  692 +
  693 + $result = DBUtil::getOneResultKey($query, 'id');
  694 +
  695 + if(empty($result)){
  696 + return PEAR::raiseError("Requested content version, $version, does not exist.");
  697 + }
  698 +
  699 + if(PEAR::isError($result)){
  700 + return $result;
  701 + }
  702 +
  703 + return $result;
  704 + }
  705 + // }}}
  706 +
  707 + // {{{ getMetadataVersionIdFromVersion
  708 + static function getMetadataVersionIdFromVersion($doc_id, $version)
  709 + {
  710 + $query = "select id from document_metadata_version where document_id = $doc_id and metadata_version = $version";
  711 +
  712 + $result = DBUtil::getOneResultKey($query, 'id');
  713 +
  714 + if(empty($result)){
  715 + return PEAR::raiseError("Requested metadata version, $version, does not exist.");
  716 + }
  717 +
  718 + if(PEAR::isError($result)){
  719 + return $result;
  720 + }
  721 +
  722 + return $result;
  723 + }
  724 + // }}}
  725 +
682 // {{{ delete 726 // {{{ delete
683 function delete() { 727 function delete() {
684 $this->_oDocumentCore->setMetadataVersionId(null); 728 $this->_oDocumentCore->setMetadataVersionId(null);
lib/documentmanagement/documentmetadataversion.inc.php
@@ -5,32 +5,32 @@ @@ -5,32 +5,32 @@
5 * KnowledgeTree Community Edition 5 * KnowledgeTree Community Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
7 * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc. 7 * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc.
8 - *  
9 - * 8 + *
  9 + *
10 * This program is free software; you can redistribute it and/or modify it under 10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License version 3 as published by the 11 * the terms of the GNU General Public License version 3 as published by the
12 * Free Software Foundation. 12 * Free Software Foundation.
13 - * 13 + *
14 * This program is distributed in the hope that it will be useful, but WITHOUT 14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * details. 17 * details.
18 - * 18 + *
19 * You should have received a copy of the GNU General Public License 19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 - *  
22 - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, 21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23 * California 94120-7775, or email info@knowledgetree.com. 23 * California 94120-7775, or email info@knowledgetree.com.
24 - * 24 + *
25 * The interactive user interfaces in modified source and object code versions 25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under 26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU General Public License version 3. 27 * Section 5 of the GNU General Public License version 3.
28 - * 28 + *
29 * In accordance with Section 7(b) of the GNU General Public License version 3, 29 * In accordance with Section 7(b) of the GNU General Public License version 3,
30 * these Appropriate Legal Notices must retain the display of the "Powered by 30 * these Appropriate Legal Notices must retain the display of the "Powered by
31 - * KnowledgeTree" logo and retain the original copyright notice. If the display of the 31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices 32 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33 - * must display the words "Powered by KnowledgeTree" and retain the original 33 + * must display the words "Powered by KnowledgeTree" and retain the original
34 * copyright notice. 34 * copyright notice.
35 * Contributor( s): ______________________________________ 35 * Contributor( s): ______________________________________
36 * 36 *
@@ -73,7 +73,7 @@ class KTDocumentMetadataVersion extends KTEntity { @@ -73,7 +73,7 @@ class KTDocumentMetadataVersion extends KTEntity {
73 var $iWorkflowStateId; 73 var $iWorkflowStateId;
74 74
75 var $_aFieldToSelect; 75 var $_aFieldToSelect;
76 - 76 +
77 public static $_versionFields = null; 77 public static $_versionFields = null;
78 78
79 // {{{ getters/setters 79 // {{{ getters/setters
@@ -101,11 +101,11 @@ class KTDocumentMetadataVersion extends KTEntity { @@ -101,11 +101,11 @@ class KTDocumentMetadataVersion extends KTEntity {
101 function getWorkflowStateId() { return $this->iWorkflowStateId; } 101 function getWorkflowStateId() { return $this->iWorkflowStateId; }
102 function setWorkflowStateId($mValue) { $this->iWorkflowStateId = $mValue; } 102 function setWorkflowStateId($mValue) { $this->iWorkflowStateId = $mValue; }
103 // }}} 103 // }}}
104 - 104 +
105 function __construct() { 105 function __construct() {
106 $this->_aFieldToSelect = KTDocumentMetaDataVersion::getFieldsToSelect(); 106 $this->_aFieldToSelect = KTDocumentMetaDataVersion::getFieldsToSelect();
107 } 107 }
108 - 108 +
109 function getFieldsToSelect() { 109 function getFieldsToSelect() {
110 if(self::$_versionFields == null) { 110 if(self::$_versionFields == null) {
111 $sTable = KTUtil::getTableName('document_metadata_version'); 111 $sTable = KTUtil::getTableName('document_metadata_version');
@@ -116,24 +116,24 @@ class KTDocumentMetadataVersion extends KTEntity { @@ -116,24 +116,24 @@ class KTDocumentMetadataVersion extends KTEntity {
116 } 116 }
117 self::$_versionFields = $result; 117 self::$_versionFields = $result;
118 } 118 }
119 - return self::$_versionFields; 119 + return self::$_versionFields;
120 } 120 }
121 - 121 +
122 function getFieldType($dbType) { 122 function getFieldType($dbType) {
123 /* Integer test */ 123 /* Integer test */
124 if(strpos($dbType, "int") !== FALSE) { 124 if(strpos($dbType, "int") !== FALSE) {
125 return "i"; 125 return "i";
126 } 126 }
127 - 127 +
128 /* Time test */ 128 /* Time test */
129 if(strpos($dbType, "time") !== FALSE) { 129 if(strpos($dbType, "time") !== FALSE) {
130 return "d"; 130 return "d";
131 } 131 }
132 - 132 +
133 /* Default */ 133 /* Default */
134 return "s"; 134 return "s";
135 } 135 }
136 - 136 +
137 137
138 function &createFromArray($aOptions) { 138 function &createFromArray($aOptions) {
139 return KTEntityUtil::createFromArray('KTDocumentMetadataVersion', $aOptions); 139 return KTEntityUtil::createFromArray('KTDocumentMetadataVersion', $aOptions);
@@ -163,7 +163,7 @@ class KTDocumentMetadataVersion extends KTEntity { @@ -163,7 +163,7 @@ class KTDocumentMetadataVersion extends KTEntity {
163 'document_id' => $iDocumentId, 163 'document_id' => $iDocumentId,
164 ), array( 164 ), array(
165 'multi' => true, 165 'multi' => true,
166 - 'orderby' => 'version_created DESC', 166 + 'orderby' => 'version_created DESC, metadata_version DESC',
167 )); 167 ));
168 } 168 }
169 169
lib/storage/ondiskhashedstoragemanager.inc.php
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 * KnowledgeTree Community Edition 8 * KnowledgeTree Community Edition
9 * Document Management Made Simple 9 * Document Management Made Simple
10 * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc. 10 * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc.
11 - * 11 + *
12 * 12 *
13 * This program is free software; you can redistribute it and/or modify it under 13 * This program is free software; you can redistribute it and/or modify it under
14 * the terms of the GNU General Public License version 3 as published by the 14 * the terms of the GNU General Public License version 3 as published by the
@@ -176,6 +176,20 @@ class KTOnDiskHashedStorageManager extends KTStorageManager { @@ -176,6 +176,20 @@ class KTOnDiskHashedStorageManager extends KTStorageManager {
176 return sprintf("%s/%s", $oConfig->get('urls/documentRoot'), $this->getPath($oDocument)); 176 return sprintf("%s/%s", $oConfig->get('urls/documentRoot'), $this->getPath($oDocument));
177 } 177 }
178 178
  179 + function temporaryFileForVersion($iVersionId) {
  180 + $oConfig =& KTConfig::getSingleton();
  181 +
  182 + // get path to the content version
  183 + $oContentVersion = KTDocumentContentVersion::get($iVersionId);
  184 + $sPath = sprintf("%s/%s", $oConfig->get('urls/documentRoot'), $this->getPath($oContentVersion));
  185 +
  186 + // Ensure the file exists
  187 + if (file_exists($sPath)) {
  188 + return $sPath;
  189 + }
  190 + return false;
  191 + }
  192 +
179 function freeTemporaryFile($sPath) { 193 function freeTemporaryFile($sPath) {
180 // Storage uses file-on-filesystem for temporaryFile 194 // Storage uses file-on-filesystem for temporaryFile
181 return; 195 return;
plugins/ktcore/KTWidgets.php
@@ -1165,6 +1165,8 @@ class KTCoreImageSelectWidget extends KTWidget { @@ -1165,6 +1165,8 @@ class KTCoreImageSelectWidget extends KTWidget {
1165 $oTemplate = $oTemplating->loadTemplate('ktcore/forms/widgets/base'); 1165 $oTemplate = $oTemplating->loadTemplate('ktcore/forms/widgets/base');
1166 1166
1167 $this->aJavascript[] = 'thirdpartyjs/jquery/jquery-1.3.2.js'; 1167 $this->aJavascript[] = 'thirdpartyjs/jquery/jquery-1.3.2.js';
  1168 + $this->aJavascript[] = 'thirdpartyjs/jquery/plugins/selectimage/jquery.selectimage.js';
  1169 + $this->aJavascript[] = 'resources/js/kt_selectimage.js';
1168 1170
1169 if (!empty($this->aJavascript)) { 1171 if (!empty($this->aJavascript)) {
1170 // grab our inner page. 1172 // grab our inner page.
@@ -1172,14 +1174,15 @@ class KTCoreImageSelectWidget extends KTWidget { @@ -1172,14 +1174,15 @@ class KTCoreImageSelectWidget extends KTWidget {
1172 $oPage->requireJSResources($this->aJavascript); 1174 $oPage->requireJSResources($this->aJavascript);
1173 } 1175 }
1174 1176
1175 - $this->aCSS[] = 'resources/css/kt_imageselect.css'; 1177 + //$this->aCSS[] = 'resources/css/kt_imageselect.css';
  1178 + $this->aCSS[] = 'thirdpartyjs/jquery/plugins/selectimage/css/selectimage.css';
1176 1179
1177 if (!empty($this->aCSS)) { 1180 if (!empty($this->aCSS)) {
1178 // grab our inner page. 1181 // grab our inner page.
1179 $oPage =& $GLOBALS['main']; 1182 $oPage =& $GLOBALS['main'];
1180 $oPage->requireCSSResources($this->aCSS); 1183 $oPage->requireCSSResources($this->aCSS);
1181 } 1184 }
1182 - 1185 +
1183 $widget_content = $this->getWidget(); 1186 $widget_content = $this->getWidget();
1184 1187
1185 $aTemplateData = array( 1188 $aTemplateData = array(
resources/js/kt_selectimage.js 0 โ†’ 100755
  1 +jQuery(document).ready(function() {
  2 + jQuery('#kt_image_select_container').selectImage();
  3 +});
sql/mysql/install/structure.sql
@@ -633,8 +633,8 @@ CREATE TABLE `download_files` ( @@ -633,8 +633,8 @@ CREATE TABLE `download_files` (
633 `session` varchar(100) NOT NULL, 633 `session` varchar(100) NOT NULL,
634 `download_date` timestamp NULL default CURRENT_TIMESTAMP, 634 `download_date` timestamp NULL default CURRENT_TIMESTAMP,
635 `downloaded` int(10) unsigned NOT NULL default '0', 635 `downloaded` int(10) unsigned NOT NULL default '0',
636 - `filesize` int(10) unsigned NOT NULL,  
637 - `content_version` int(10) unsigned NOT NULL, 636 + `filesize` int(10) unsigned,
  637 + `content_version` int(10) unsigned,
638 `hash` varchar(100) NOT NULL, 638 `hash` varchar(100) NOT NULL,
639 PRIMARY KEY (`document_id`,`session`), 639 PRIMARY KEY (`document_id`,`session`),
640 CONSTRAINT `download_files_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE 640 CONSTRAINT `download_files_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
sql/mysql/upgrade/3.7.0.4/download_files.sql 0 โ†’ 100644
  1 +ALTER TABLE download_files CHANGE COLUMN content_version content_version int(10) unsigned, CHANGE COLUMN filesize filesize int(10) unsigned;
0 \ No newline at end of file 2 \ No newline at end of file
templates/ktcore/forms/widgets/imageselect.smarty
@@ -2,32 +2,17 @@ @@ -2,32 +2,17 @@
2 <field> 2 <field>
3 <div id="kt_image_select_container"> 3 <div id="kt_image_select_container">
4 4
5 - {foreach key=id item=src from=$value} 5 + <input type="hidden" id="selectimage_src" name="selectimage_src" value="">
  6 + <input type="hidden" id="selectimage_alt" name="selectimage_alt" value="">
  7 + <input type="hidden" id="selectimage_title" name="selectimage_title" value="">
  8 + <input type="hidden" id="selectimage_name" name="selectimage_name" value="">
  9 + <input type="hidden" id="selectimage_id" name="selectimage_id" value="">
6 10
7 - <div class="jq_select_image">  
8 - <img class="kt_image_select" id="kt_image_select_{$id}" src="{$src}" border="0"/>  
9 - </div>  
10 - <script type="text/javascript">  
11 - var toggle_{$id} = 1;  
12 - var selected = '';  
13 -  
14 - var multiselect = false;  
15 -  
16 - var hover = '#f9f9f9';  
17 - var click = '#f2943a'; //Orange  
18 - var background_color = 'white'; //also set in css  
19 -  
20 - jQuery('#kt_image_select_{$id}').click(function(){ldelim}  
21 - jQuery('#kt_image_select').val('{$src}');  
22 -  
23 - //Resetting background:  
24 - jQuery("img[id*='kt_image_select_']").css('border', '10px solid ' + background_color);  
25 - jQuery('#kt_image_select_{$id}').css('border', '10px solid ' + click);  
26 -  
27 - {rdelim})  
28 - </script>  
29 -  
30 - {/foreach} 11 + {foreach key=id item=src from=$value}
  12 + <div class="jq_select_image">
  13 + <img class="kt_image_select" id="kt_image_select_{$id}" src="{$src}" border="0"/>
  14 + </div>
  15 + {/foreach}
31 16
32 </div> 17 </div>
33 18
tests/runtests.php
@@ -36,12 +36,12 @@ class UnitTests extends TestSuite { @@ -36,12 +36,12 @@ class UnitTests extends TestSuite {
36 // if Electronic Signatures are NOT enabled for the API, new tests may not 36 // if Electronic Signatures are NOT enabled for the API, new tests may not
37 // include the check which allows the tests to be bypassed when esignatures 37 // include the check which allows the tests to be bypassed when esignatures
38 // are not on, so if you have failures, check there first :) 38 // are not on, so if you have failures, check there first :)
39 - $this->addFile('api/testElectronicSignatures.php'); 39 +// $this->addFile('api/testElectronicSignatures.php');
40 40
41 // Web Service tests 41 // Web Service tests
42 $this->addFile('webservices/testRest.php'); 42 $this->addFile('webservices/testRest.php');
43 - $this->addFile('webservices/testSoap.php');  
44 - 43 + $this->addFile('webservices/testSoap.php');
  44 +
45 // $this->addFile('SQLFile/test_sqlfile.php'); 45 // $this->addFile('SQLFile/test_sqlfile.php');
46 // $this->addFile('cache/testCache.php'); 46 // $this->addFile('cache/testCache.php');
47 // $this->addFile('config/testConfig.php'); 47 // $this->addFile('config/testConfig.php');
tests/webservices/testSoap.php
@@ -16,10 +16,14 @@ class SOAPTestCase extends KTUnitTestCase { @@ -16,10 +16,14 @@ class SOAPTestCase extends KTUnitTestCase {
16 * @var string $rootUrl The root server url for the rest web service 16 * @var string $rootUrl The root server url for the rest web service
17 */ 17 */
18 var $rootUrl; 18 var $rootUrl;
19 - 19 + var $uploads_dir;
  20 +
20 public $client; 21 public $client;
21 private $user; 22 private $user;
22 private $pass; 23 private $pass;
  24 + private $content = 'New document for testing the soap webservice api';
  25 + private $content_update = 'Updated document for testing the soap webservice api';
  26 + private $reason = 'Running unit tests';
23 27
24 /** 28 /**
25 * This method sets up the server url 29 * This method sets up the server url
@@ -31,6 +35,10 @@ class SOAPTestCase extends KTUnitTestCase { @@ -31,6 +35,10 @@ class SOAPTestCase extends KTUnitTestCase {
31 $this->rootUrl = $url.'/ktwebservice/webservice.php?'; 35 $this->rootUrl = $url.'/ktwebservice/webservice.php?';
32 $this->user = isset($_GET['user']) ? $_GET['user'] : 'admin'; 36 $this->user = isset($_GET['user']) ? $_GET['user'] : 'admin';
33 $this->pass = isset($_GET['pass']) ? $_GET['pass'] : 'admin'; 37 $this->pass = isset($_GET['pass']) ? $_GET['pass'] : 'admin';
  38 +
  39 + // Login and authenticate
  40 + $this->connect();
  41 + $this->login('127.0.0.1');
34 } 42 }
35 43
36 /** 44 /**
@@ -38,15 +46,17 @@ class SOAPTestCase extends KTUnitTestCase { @@ -38,15 +46,17 @@ class SOAPTestCase extends KTUnitTestCase {
38 */ 46 */
39 public function tearDown() 47 public function tearDown()
40 { 48 {
  49 + // Logout
  50 + $this->logout();
41 } 51 }
42 52
43 - function connect() 53 + private function connect()
44 { 54 {
45 $wsdl = $this->rootUrl . "wsdl"; 55 $wsdl = $this->rootUrl . "wsdl";
46 $this->client = new SoapClient($wsdl); 56 $this->client = new SoapClient($wsdl);
47 } 57 }
48 58
49 - function login($ip = null) 59 + private function login($ip = null)
50 { 60 {
51 $res = $this->client->__soapCall("login", array($this->user, $this->pass, $ip)); 61 $res = $this->client->__soapCall("login", array($this->user, $this->pass, $ip));
52 if($res->status_code != 0){ 62 if($res->status_code != 0){
@@ -55,67 +65,210 @@ class SOAPTestCase extends KTUnitTestCase { @@ -55,67 +65,210 @@ class SOAPTestCase extends KTUnitTestCase {
55 $this->session = $res->message; 65 $this->session = $res->message;
56 } 66 }
57 67
  68 + private function logout()
  69 + {
  70 + $result = $this->client->__soapCall("logout", array($this->session));
  71 + if($result->status_code != 0){
  72 + return true;
  73 + }
  74 + }
58 75
59 - function getDocTypes() 76 + private function getDocTypes()
60 { 77 {
61 $result = $this->client->__soapCall("get_document_types", array($this->session)); 78 $result = $this->client->__soapCall("get_document_types", array($this->session));
62 return $result->document_types; 79 return $result->document_types;
63 } 80 }
64 81
65 - function search($expr) 82 + private function search($expr)
66 { 83 {
67 $result = $this->client->__soapCall("search", array($this->session, $expr, '')); 84 $result = $this->client->__soapCall("search", array($this->session, $expr, ''));
68 return $result->hits; 85 return $result->hits;
69 } 86 }
70 87
71 - function getFolderDetail($folder, $parentId = 1) 88 + private function getFolderDetail($folder, $parentId = 1)
72 { 89 {
73 $result = $this->client->__soapCall("get_folder_detail_by_name", array($this->session, $folder, $parentId)); 90 $result = $this->client->__soapCall("get_folder_detail_by_name", array($this->session, $folder, $parentId));
74 return $result; 91 return $result;
75 } 92 }
76 93
77 - function createFolder($parent_id, $folder) 94 + private function createFolder($parent_id, $folder)
78 { 95 {
79 $result = $this->client->__soapCall("create_folder", array($this->session, $parent_id, $folder)); 96 $result = $this->client->__soapCall("create_folder", array($this->session, $parent_id, $folder));
80 return $result; 97 return $result;
81 } 98 }
82 99
83 - function deleteFolder($folder_id) 100 + private function createFolderShortcut($target_folder_id, $source_folder_id)
84 { 101 {
85 - $result = $this->client->__soapCall("delete_folder", array($this->session, "$folder_id", 'Testing')); 102 + $result = $this->client->__soapCall("create_folder_shortcut", array($this->session, $target_folder_id, $source_folder_id));
86 return $result; 103 return $result;
87 } 104 }
88 105
89 - function logout() 106 + private function deleteFolder($folder_id)
90 { 107 {
91 - $result = $this->client->__soapCall("logout", array($this->session));  
92 - if($result->status_code != 0){  
93 - return true;  
94 - } 108 + $result = $this->client->__soapCall("delete_folder", array($this->session, $folder_id, 'Testing'));
  109 + return $result;
  110 + }
  111 +
  112 + private function getFolderShortcuts($folder_id)
  113 + {
  114 + $result = $this->client->__soapCall("get_folder_shortcuts", array($this->session, $folder_id));
  115 + return $result;
  116 + }
  117 +
  118 + private function getDocumentVersionHistory($document_id)
  119 + {
  120 + $result = $this->client->__soapCall("get_document_version_history", array($this->session, $document_id));
  121 + return $result;
  122 + }
  123 +
  124 + private function createDocument($folder_id, $title, $filename, $documenttype = 'Default')
  125 + {
  126 + global $default;
  127 + $uploads_dir = $default->uploadDirectory;
  128 +
  129 + // create document in uploads folder
  130 + $tempfilename = tempnam($uploads_dir, 'myfile');
  131 + $fp = fopen($tempfilename, 'wt');
  132 + fwrite($fp, $this->content);
  133 + fclose($fp);
  134 +
  135 + // call add document to upload into repo
  136 + $result = $this->client->__soapCall("add_document", array($this->session, $folder_id, $title, $filename, $documenttype, $tempfilename));
  137 + return $result;
  138 + }
  139 +
  140 + private function createSmallDocument($folder_id, $title, $filename, $documenttype = 'Default')
  141 + {
  142 + global $default;
  143 + $uploads_dir = $default->uploadDirectory;
  144 +
  145 + // create document in uploads folder
  146 + $base64 = base64_encode($this->content);
  147 +
  148 + // call add document to upload into repo
  149 + $result = $this->client->__soapCall("add_small_document", array($this->session, $folder_id, $title, $filename, $documenttype, $base64));
  150 + return $result;
  151 + }
  152 +
  153 + private function checkinDocument($document_id, $filename, $major_update = false)
  154 + {
  155 + global $default;
  156 + $uploads_dir = $default->uploadDirectory;
  157 +
  158 + // create document in uploads folder
  159 + $tempfilename = tempnam($uploads_dir, 'myfile');
  160 + $fp = fopen($tempfilename, 'wt');
  161 + fwrite($fp, $this->content_update);
  162 + fclose($fp);
  163 +
  164 + // call add document to upload into repo
  165 + $result = $this->client->__soapCall("checkin_document", array($this->session, $document_id, $filename, $this->reason, $tempfilename, $major_update));
  166 + return $result;
  167 + }
  168 +
  169 + private function checkinSmallDocument($document_id, $filename, $major_update = false)
  170 + {
  171 + global $default;
  172 + $uploads_dir = $default->uploadDirectory;
  173 +
  174 + // encode as base64
  175 + $base64 = base64_encode($this->content_update);
  176 +
  177 + // call add document to upload into repo
  178 + $result = $this->client->__soapCall("checkin_small_document", array($this->session, $document_id, $filename, $this->reason, $base64, $major_update));
  179 + return $result;
95 } 180 }
96 -  
97 - // now the test functions  
98 - 181 +
  182 + private function checkoutDocument($document_id, $download = true)
  183 + {
  184 + $result = $this->client->__soapCall("checkout_document", array($this->session, $document_id, $this->reason, $download));
  185 + return $result;
  186 + }
  187 +
  188 + private function checkoutSmallDocument($document_id, $download = true)
  189 + {
  190 + $result = $this->client->__soapCall("checkout_small_document", array($this->session, $document_id, $this->reason, $download));
  191 + return $result;
  192 + }
  193 +
  194 + private function createDocumentShortcut($folder_id, $target_document_id)
  195 + {
  196 + $result = $this->client->__soapCall("create_document_shortcut", array($this->session, $folder_id, $target_document_id));
  197 + return $result;
  198 + }
  199 +
  200 + private function getDocumentShortcuts($document_id)
  201 + {
  202 + $result = $this->client->__soapCall("get_document_shortcuts", array($this->session, $document_id));
  203 + return $result;
  204 + }
  205 +
  206 + private function getFolderContents($folder_id, $depth=1, $what='DFS')
  207 + {
  208 + $result = $this->client->__soapCall("get_folder_contents", array($this->session, $folder_id, $depth, $what));
  209 + return $result;
  210 + }
  211 +
  212 + private function getDocumentMetadata($document_id, $version = null)
  213 + {
  214 + $result = $this->client->__soapCall("get_document_metadata", array($this->session, $document_id, $version));
  215 + return $result;
  216 + }
  217 +
  218 + private function updateDocumentMetadata($document_id, $metadata, $sysdata=null)
  219 + {
  220 + $result = $this->client->__soapCall("update_document_metadata", array($this->session, $document_id, $metadata, $sysdata));
  221 + return $result;
  222 + }
  223 +
  224 + private function downloadDocument($document_id, $version = null)
  225 + {
  226 + $result = $this->client->__soapCall("download_document", array($this->session, $document_id, $version));
  227 + return $result;
  228 + }
  229 +
  230 + private function downloadSmallDocument($document_id, $version = null)
  231 + {
  232 + $result = $this->client->__soapCall("download_small_document", array($this->session, $document_id, $version));
  233 + return $result;
  234 + }
  235 +
  236 + private function doDownload($url)
  237 + {
  238 + $ch = curl_init($url);
  239 + curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
  240 + curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
  241 + curl_setopt($ch,CURLOPT_FOLLOWLOCATION, true);
  242 + curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
  243 +
  244 + $download = curl_exec($ch);
  245 + $status = curl_getinfo($ch,CURLINFO_HTTP_CODE);
  246 +
  247 + $error = curl_errno($ch);
  248 +
  249 + curl_close($ch);
  250 +
  251 + return array('status' => $status, 'error' => $error, 'download' => $download);
  252 + }
  253 +
  254 + /* *** now the test functions *** */
  255 +
99 /** 256 /**
100 * Tests finding of a folder or folder detail by name 257 * Tests finding of a folder or folder detail by name
101 * Runs the following sub-tests: 258 * Runs the following sub-tests:
102 * . Folder Detail by Name in root folder (no duplicate names) 259 * . Folder Detail by Name in root folder (no duplicate names)
103 * . Folder Detail by Name in subfolder of root folder (no duplicate names) 260 * . Folder Detail by Name in subfolder of root folder (no duplicate names)
104 * . Folder Detail by Name in subfolder of root folder (duplicate names) 261 * . Folder Detail by Name in subfolder of root folder (duplicate names)
105 - * 262 + *
106 * NOTE there are less tests here because we cannot test the get_folder_by_name function since it does not exist within the web service code 263 * NOTE there are less tests here because we cannot test the get_folder_by_name function since it does not exist within the web service code
107 */ 264 */
108 public function testGetFolderByName() 265 public function testGetFolderByName()
109 { 266 {
110 - // Login and authenticate  
111 - $this->connect();  
112 - $this->login('127.0.0.1');  
113 -  
114 // set up 267 // set up
115 $root_folder_id = array(); 268 $root_folder_id = array();
116 $sub_folder_id = array(); 269 $sub_folder_id = array();
117 $folders[0][1] = 'Root Folder'; 270 $folders[0][1] = 'Root Folder';
118 - 271 +
119 // Create a sub folder in the root folder 272 // Create a sub folder in the root folder
120 $parentId = 1; 273 $parentId = 1;
121 $folderName = 'Test api sub-folder ONE'; 274 $folderName = 'Test api sub-folder ONE';
@@ -124,7 +277,7 @@ class SOAPTestCase extends KTUnitTestCase { @@ -124,7 +277,7 @@ class SOAPTestCase extends KTUnitTestCase {
124 $folders[$parentId][$response->id] = $folderName; 277 $folders[$parentId][$response->id] = $folderName;
125 $this->assertEqual($response->status_code, 0); 278 $this->assertEqual($response->status_code, 0);
126 $this->assertFalse(!empty($response->message)); 279 $this->assertFalse(!empty($response->message));
127 - 280 +
128 // Create a second sub folder in the root folder 281 // Create a second sub folder in the root folder
129 $parentId = 1; 282 $parentId = 1;
130 $folderName = 'Test api sub-folder TWO'; 283 $folderName = 'Test api sub-folder TWO';
@@ -133,7 +286,7 @@ class SOAPTestCase extends KTUnitTestCase { @@ -133,7 +286,7 @@ class SOAPTestCase extends KTUnitTestCase {
133 $folders[$parentId][$response->id] = $folderName; 286 $folders[$parentId][$response->id] = $folderName;
134 $this->assertEqual($response->status_code, 0); 287 $this->assertEqual($response->status_code, 0);
135 $this->assertFalse(!empty($response->message)); 288 $this->assertFalse(!empty($response->message));
136 - 289 +
137 // Create a sub folder in the first sub folder 290 // Create a sub folder in the first sub folder
138 $parentId = $root_folder_id[0]; 291 $parentId = $root_folder_id[0];
139 $folderName = 'Test api sub-folder THREE'; 292 $folderName = 'Test api sub-folder THREE';
@@ -142,7 +295,7 @@ class SOAPTestCase extends KTUnitTestCase { @@ -142,7 +295,7 @@ class SOAPTestCase extends KTUnitTestCase {
142 $folders[$parentId][$response->id] = $folderName; 295 $folders[$parentId][$response->id] = $folderName;
143 $this->assertEqual($response->status_code, 0); 296 $this->assertEqual($response->status_code, 0);
144 $this->assertFalse(!empty($response->message)); 297 $this->assertFalse(!empty($response->message));
145 - 298 +
146 // Create a sub folder within the first sub folder which shares a name with one of the root sub folders 299 // Create a sub folder within the first sub folder which shares a name with one of the root sub folders
147 $parentId = $sub_folder_id[0][0]; 300 $parentId = $sub_folder_id[0][0];
148 $folderName = 'Test api sub-folder TWO'; 301 $folderName = 'Test api sub-folder TWO';
@@ -151,7 +304,7 @@ class SOAPTestCase extends KTUnitTestCase { @@ -151,7 +304,7 @@ class SOAPTestCase extends KTUnitTestCase {
151 $folders[$parentId][$response->id] = $folderName; 304 $folders[$parentId][$response->id] = $folderName;
152 $this->assertEqual($response->status_code, 0); 305 $this->assertEqual($response->status_code, 0);
153 $this->assertFalse(!empty($response->message)); 306 $this->assertFalse(!empty($response->message));
154 - 307 +
155 // Create a second sub folder in the first sub folder 308 // Create a second sub folder in the first sub folder
156 $parentId = $root_folder_id[0]; 309 $parentId = $root_folder_id[0];
157 $folderName = 'Test api sub-folder FOUR'; 310 $folderName = 'Test api sub-folder FOUR';
@@ -169,7 +322,7 @@ class SOAPTestCase extends KTUnitTestCase { @@ -169,7 +322,7 @@ class SOAPTestCase extends KTUnitTestCase {
169 $folders[$parentId][$response->id] = $folderName; 322 $folders[$parentId][$response->id] = $folderName;
170 $this->assertEqual($response->status_code, 0); 323 $this->assertEqual($response->status_code, 0);
171 $this->assertFalse(!empty($response->message)); 324 $this->assertFalse(!empty($response->message));
172 - 325 +
173 // Create a sub folder within the second sub folder which shares a name with a sub folder in the first sub folder 326 // Create a sub folder within the second sub folder which shares a name with a sub folder in the first sub folder
174 $parentId = $sub_folder_id[1][0]; 327 $parentId = $sub_folder_id[1][0];
175 $folderName = 'Test api sub-folder THREE'; 328 $folderName = 'Test api sub-folder THREE';
@@ -180,7 +333,7 @@ class SOAPTestCase extends KTUnitTestCase { @@ -180,7 +333,7 @@ class SOAPTestCase extends KTUnitTestCase {
180 $this->assertFalse(!empty($response->message)); 333 $this->assertFalse(!empty($response->message));
181 334
182 // NOTE default parent is 1, so does not need to be declared when searching the root folder, but we use it elsewhere 335 // NOTE default parent is 1, so does not need to be declared when searching the root folder, but we use it elsewhere
183 - 336 +
184 // Fetching of root folder 337 // Fetching of root folder
185 $parentId = 0; 338 $parentId = 0;
186 $folderName = 'Root Folder'; 339 $folderName = 'Root Folder';
@@ -190,7 +343,7 @@ class SOAPTestCase extends KTUnitTestCase { @@ -190,7 +343,7 @@ class SOAPTestCase extends KTUnitTestCase {
190 if (($response->status_code == 0)) { 343 if (($response->status_code == 0)) {
191 $this->assertEqual($folders[$parentId][$response->id], $folderName); 344 $this->assertEqual($folders[$parentId][$response->id], $folderName);
192 } 345 }
193 - 346 +
194 // Folder Detail by Name in root folder (no duplicate names) 347 // Folder Detail by Name in root folder (no duplicate names)
195 $parentId = 1; 348 $parentId = 1;
196 $folderName = 'Test api sub-folder ONE'; 349 $folderName = 'Test api sub-folder ONE';
@@ -201,7 +354,7 @@ class SOAPTestCase extends KTUnitTestCase { @@ -201,7 +354,7 @@ class SOAPTestCase extends KTUnitTestCase {
201 if (($response->status_code == 0)) { 354 if (($response->status_code == 0)) {
202 $this->assertEqual($folders[$parentId][$response->id], $folderName); 355 $this->assertEqual($folders[$parentId][$response->id], $folderName);
203 } 356 }
204 - 357 +
205 // Folder Detail by Name in sub folder of root folder (no duplicate names) 358 // Folder Detail by Name in sub folder of root folder (no duplicate names)
206 $parentId = $root_folder_id[0]; 359 $parentId = $root_folder_id[0];
207 $folderName = 'Test api sub-folder FOUR'; 360 $folderName = 'Test api sub-folder FOUR';
@@ -211,7 +364,7 @@ class SOAPTestCase extends KTUnitTestCase { @@ -211,7 +364,7 @@ class SOAPTestCase extends KTUnitTestCase {
211 if (($response->status_code == 0)) { 364 if (($response->status_code == 0)) {
212 $this->assertEqual($folders[$parentId][$response->id], $folderName); 365 $this->assertEqual($folders[$parentId][$response->id], $folderName);
213 } 366 }
214 - 367 +
215 // Folder Detail by Name in root folder (duplicate names) 368 // Folder Detail by Name in root folder (duplicate names)
216 $parentId = 1; 369 $parentId = 1;
217 $folderName = 'Test api sub-folder TWO'; 370 $folderName = 'Test api sub-folder TWO';
@@ -221,7 +374,7 @@ class SOAPTestCase extends KTUnitTestCase { @@ -221,7 +374,7 @@ class SOAPTestCase extends KTUnitTestCase {
221 if (($response->status_code == 0)) { 374 if (($response->status_code == 0)) {
222 $this->assertEqual($folders[$parentId][$response->id], $folderName); 375 $this->assertEqual($folders[$parentId][$response->id], $folderName);
223 } 376 }
224 - 377 +
225 // Folder Detail by Name in sub folder of root folder (duplicate names) 378 // Folder Detail by Name in sub folder of root folder (duplicate names)
226 $parentId = $root_folder_id[0]; 379 $parentId = $root_folder_id[0];
227 $folderName = 'Test api sub-folder THREE'; 380 $folderName = 'Test api sub-folder THREE';
@@ -231,7 +384,7 @@ class SOAPTestCase extends KTUnitTestCase { @@ -231,7 +384,7 @@ class SOAPTestCase extends KTUnitTestCase {
231 if (($response->status_code == 0)) { 384 if (($response->status_code == 0)) {
232 $this->assertEqual($folders[$parentId][$response->id], $folderName); 385 $this->assertEqual($folders[$parentId][$response->id], $folderName);
233 } 386 }
234 - 387 +
235 // Negative test with non duplicated folder - look for folder in location it does not exist 388 // Negative test with non duplicated folder - look for folder in location it does not exist
236 $parentId = $root_folder_id[0]; 389 $parentId = $root_folder_id[0];
237 $folderName = 'Test api sub-folder ONE'; 390 $folderName = 'Test api sub-folder ONE';
@@ -239,7 +392,7 @@ class SOAPTestCase extends KTUnitTestCase { @@ -239,7 +392,7 @@ class SOAPTestCase extends KTUnitTestCase {
239 $this->assertNotEqual($response->status_code, 0); 392 $this->assertNotEqual($response->status_code, 0);
240 $this->assertTrue(!empty($response->message)); 393 $this->assertTrue(!empty($response->message));
241 $this->assertNotEqual($folders[$parentId][$response->id], $folderName); 394 $this->assertNotEqual($folders[$parentId][$response->id], $folderName);
242 - 395 +
243 // Negative test with duplicated folder - look for folder with incorrect parent id, result should not match expected folder 396 // Negative test with duplicated folder - look for folder with incorrect parent id, result should not match expected folder
244 $parentId = 1; 397 $parentId = 1;
245 $actualParentId = $sub_folder_id[0][0]; 398 $actualParentId = $sub_folder_id[0][0];
@@ -251,15 +404,511 @@ class SOAPTestCase extends KTUnitTestCase { @@ -251,15 +404,511 @@ class SOAPTestCase extends KTUnitTestCase {
251 // but not the one we wanted 404 // but not the one we wanted
252 $expectedResponse = $this->getFolderDetail($folderName, $actualParentId); 405 $expectedResponse = $this->getFolderDetail($folderName, $actualParentId);
253 $this->assertNotEqual($response->id, $expectedResponse->id); 406 $this->assertNotEqual($response->id, $expectedResponse->id);
254 - 407 +
255 // Clean up - delete all of the folders 408 // Clean up - delete all of the folders
256 foreach ($root_folder_id as $folder_id) { 409 foreach ($root_folder_id as $folder_id) {
257 $this->deleteFolder($folder_id); 410 $this->deleteFolder($folder_id);
258 } 411 }
259 -  
260 - // Logout  
261 - $this->logout();  
262 } 412 }
263 413
  414 + /**
  415 + * Tests the creation of folders and folder shortcuts, getting the folder shortcut(s)
  416 + * WebService V3 and higher
  417 + */
  418 + public function testCreateFolderShortcut()
  419 + {
  420 + // if V3
  421 + if(LATEST_WEBSERVICE_VERSION < 3){
  422 + return ;
  423 + }
  424 +
  425 + // Create folder 1
  426 + $result = $this->createFolder(1, 'Test Shortcut Container');
  427 + $this->assertEqual($result->status_code, 0, 'Create folder - '.$result->message);
  428 + $parentFolderId = $result->id;
  429 +
  430 + // Create folder 2
  431 + $result = $this->createFolder(1, 'Test Shortcut Target');
  432 + $this->assertEqual($result->status_code, 0, 'Create folder - '.$result->message);
  433 + $targetFolderId = $result->id;
  434 +
  435 + // Create folder 3
  436 + $result = $this->createFolder($targetFolderId, 'Test Shortcut Target 2');
  437 + $this->assertEqual($result->status_code, 0, 'Create folder - '.$result->message);
  438 + $target2FolderId = $result->id;
  439 +
  440 + // Create shortcut in folder 1 targeting folder 2
  441 + $result = $this->createFolderShortcut($parentFolderId, $targetFolderId);
  442 + $this->assertEqual($result->status_code, 0, 'Create folder Shortcut - '.$result->message);
  443 +
  444 + $shortcutId = $result->id;
  445 + $linkedFolderId = $result->linked_folder_id;
  446 + $this->assertTrue(is_numeric($shortcutId), 'Shortcut id should be numeric');
  447 + $this->assertTrue(is_numeric($linkedFolderId), 'Linked folder id should be numeric');
  448 + $this->assertEqual($linkedFolderId, $targetFolderId, 'Shortcut should contain link the target folder');
  449 +
  450 + // Create shortcut in folder 1 targeting folder 3
  451 + $result = $this->createFolderShortcut($parentFolderId, $target2FolderId);
  452 + $this->assertEqual($result->status_code, 0, 'Create folder shortcut - '.$result->message);
  453 +
  454 + $shortcut2Id = $result->id;
  455 + $linkedFolder2Id = $result->linked_folder_id;
  456 + $this->assertTrue(is_numeric($shortcut2Id), 'Shortcut id should be numeric');
  457 + $this->assertTrue(is_numeric($linkedFolder2Id), 'Linked folder id should be numeric');
  458 + $this->assertEqual($linkedFolder2Id, $target2FolderId, 'Shortcut should contain link the target folder');
  459 +
  460 + // Get the folder shortcut details
  461 + $result = $this->getFolderShortcuts($targetFolderId);
  462 + $this->assertEqual($result->status_code, 0, 'Should return list of folder shortcuts - '.$result->message);
  463 +
  464 + $shortcuts = $result[1];
  465 + foreach ($shortcuts as $item) {
  466 + $this->assertEqual($item->id, $shortcutId);
  467 + $this->assertEqual($item->linked_folder_id, $targetFolderId);
  468 + }
  469 +
  470 + $result = $this->getFolderShortcuts($target2FolderId);
  471 + $this->assertEqual($result->status_code, 0, 'Should return list of folder shortcuts - '.$result->message);
  472 +
  473 + $shortcuts2 = $result[1];
  474 + foreach ($shortcuts2 as $item) {
  475 + $this->assertEqual($item->id, $shortcut2Id);
  476 + $this->assertEqual($item->linked_folder_id, $target2FolderId);
  477 + }
  478 +
  479 + // delete and cleanup
  480 + $this->deleteFolder($parentFolderId);
  481 + $this->deleteFolder($targetFolderId);
  482 + }
  483 +
  484 + /**
  485 + * Tests the document upload and the creation and retrieval of document shortcuts
  486 + * WS V3
  487 + */
  488 + public function testCreateDocumentShortcut()
  489 + {
  490 + // if V3
  491 + if(LATEST_WEBSERVICE_VERSION < 3){
  492 + //$this->assertEqual(LATEST_WEBSERVICE_VERSION, 3, 'Webservice version is less than 3. Exiting test, functionality is V3 only');
  493 + return ;
  494 + }
  495 +
  496 + // Create folder 1 containing the shortcut
  497 + $result = $this->createFolder(1, 'Test Shortcut Container');
  498 + $this->assertEqual($result->status_code, 0, 'Create folder - '.$result->message);
  499 + $parentFolderId = $result->id;
  500 +
  501 + // Create folder 2 containing the document
  502 + $result = $this->createFolder(1, 'Test Shortcut Target');
  503 + $this->assertEqual($result->status_code, 0, 'Create folder - '.$result->message);
  504 + $targetFolderId = $result->id;
  505 +
  506 + // Upload document to folder 2
  507 + $result = $this->createDocument($targetFolderId, 'Target Doc', 'target.txt');
  508 + $this->assertEqual($result->status_code, 0, 'Create document - '.$result->message);
  509 + $documentId = $result->document_id;
  510 + $this->assertTrue(is_numeric($documentId), 'Document id should be numeric');
  511 +
  512 + // Create shortcut in folder 1, pointing to the document in folder 2
  513 + $result = $this->createDocumentShortcut($parentFolderId, $documentId);
  514 + $this->assertEqual($result->status_code, 0, 'Create document shortcut - '.$result->message);
  515 + $shortcutId = $result->document_id;
  516 + $linkedDocumentId = $result->linked_document_id;
  517 + $this->assertTrue(is_numeric($shortcutId), 'Shortcut id should be numeric');
  518 + $this->assertTrue(is_numeric($linkedDocumentId), 'Linked document id should be numeric');
  519 + $this->assertEqual($linkedDocumentId, $documentId, 'Shortcut should contain link to the target document');
  520 +
  521 + // delete and cleanup
  522 + $this->deleteFolder($parentFolderId);
  523 + $this->deleteFolder($targetFolderId);
  524 + }
  525 +
  526 + /**
  527 + * Tests document uploads, checkin / checkout, downloads and document version downloads (V3)
  528 + * Normal documents and small / base64 documents
  529 + */
  530 + public function testUploadDownloadDocument()
  531 + {
  532 + // Create folder containing the documents
  533 + $result = $this->createFolder(1, 'Test Container');
  534 + $this->assertEqual($result->status_code, 0, 'Create folder - '.$result->message);
  535 + $folderId = $result->id;
  536 +
  537 + // Upload document to folder
  538 + $filename = 'test_doc.txt';
  539 + $result = $this->createDocument($folderId, 'Test Doc', $filename);
  540 + $this->assertEqual($result->status_code, 0, 'Create document - '.$result->message);
  541 + $documentId = $result->document_id;
  542 + $this->assertTrue(is_numeric($documentId), 'Document id should be numeric');
  543 +
  544 + // Get the download url for the document
  545 + $result = $this->downloadDocument($documentId);
  546 + $this->assertEqual($result->status_code, 0, 'Get document download url - '.$result->message);
  547 + $url = $result->message;
  548 + $this->assertTrue(is_string($url), 'URL should be a string');
  549 + $this->assertTrue(strpos($url, 'http') !== false, 'URL should contain http');
  550 +
  551 + // Download the document
  552 + $result = $this->doDownload($url);
  553 + $this->assertEqual($result['status'], 200, 'Status should be code 200 for success - '.$result['status']);
  554 + $this->assertEqual($result['error'], 0, 'Error code should be 0 for success - '.$result['error']);
  555 + $this->assertEqual($result['download'], $this->content, 'Document content should be the same as that uploaded');
  556 +
  557 + // ----------
  558 +
  559 + // Upload base64 document to folder
  560 + $filename2 = 'test_base64_doc.txt';
  561 + $result = $this->createSmallDocument($folderId, 'Test Base64 Doc', $filename2);
  562 + $this->assertEqual($result->status_code, 0, 'Create base64 document - '.$result->message);
  563 + $documentId2 = $result->document_id;
  564 + $this->assertTrue(is_numeric($documentId2), 'Document id should be numeric');
  565 +
  566 + // Download base64 document
  567 + $result = $this->downloadSmallDocument($documentId2);
  568 + $this->assertEqual($result->status_code, 0, 'Download small document - '.$result->message);
  569 + $content = $result->message;
  570 + $this->assertTrue(is_string($content), 'Content should be a string');
  571 + $content = base64_decode($content);
  572 + $this->assertEqual($content, $this->content, 'Document content should be the same as that uploaded');
  573 +
  574 + if(LATEST_WEBSERVICE_VERSION < 3){
  575 + // delete and cleanup
  576 + $this->deleteFolder($folderId);
  577 + return ;
  578 + }
  579 +
  580 + /* *** V3 functions *** */
  581 +
  582 + // Checkout first document
  583 + $result = $this->checkoutDocument($documentId);
  584 + $this->assertEqual($result->status_code, 0, 'Checkout document - '.$result->message);
  585 + $checkoutBy = $result->checked_out_by;
  586 + $checkoutDate = $result->checked_out_date;
  587 + $url = $result->message;
  588 + $this->assertFalse(is_null($checkoutDate), 'Checked out date should not be null / empty - '.$checkoutDate);
  589 + $this->assertEqual($checkoutBy, 'Administrator', 'Using the Administrative user, checked out user must match - '.$checkoutBy);
  590 + $this->assertTrue(is_string($url), 'Download URL should be a string');
  591 + $this->assertTrue(strpos($url, 'http') !== false, 'Download URL should contain http');
  592 +
  593 + // Download the document
  594 + $result = $this->doDownload($url);
  595 + $content = $result['download'];
  596 + $this->assertEqual($result['status'], 200, 'Status should be code 200 for success - '.$result['status']);
  597 + $this->assertEqual($result['error'], 0, 'Error code should be 0 for success - '.$result['error']);
  598 + $this->assertEqual($result['download'], $this->content, 'Document content should be the same as that uploaded');
  599 +
  600 + // ----------
  601 +
  602 + // Checkin a new version
  603 + $result = $this->checkinDocument($documentId, $filename);
  604 + $this->assertEqual($result->status_code, 0, 'Checkin document - '.$result->message);
  605 + $checkoutBy = $result->checked_out_by;
  606 + $this->assertTrue(empty($checkoutBy) || $checkoutBy == 'n/a', 'Document should no longer be checked out by anyone - '.$checkoutBy);
  607 +
  608 + // Download new version
  609 + $result = $this->downloadDocument($documentId);
  610 + $this->assertEqual($result->status_code, 0, 'Get checkedin document download url - '.$result->message);
  611 + $url = $result->message;
  612 +
  613 + // Download the document
  614 + $result = $this->doDownload($url);
  615 + $this->assertEqual($result['download'], $this->content_update, 'Document content should be the same as the updated content');
  616 +
  617 + // ----------
  618 +
  619 + // Get previous versions of the document
  620 + $result = $this->getDocumentVersionHistory($documentId);
  621 + $this->assertEqual($result->status_code, 0, 'Get document version history - '.$result->message);
  622 + $history = $result->history;
  623 + $this->assertTrue(is_array($history), 'Version history should be an array');
  624 + $this->assertEqual(count($history), 2, 'Version history should contain 2 items / versions');
  625 +
  626 + // Get the previous version number
  627 + $version = isset($history[1]) ? $history[1]->content_version : null;
  628 +
  629 + // Download previous version
  630 + $result = $this->downloadDocument($documentId, $version);
  631 + $this->assertEqual($result->status_code, 0, "Get document download url for previous version ($version) - ".$result->message);
  632 + $url = $result->message;
  633 +
  634 + // Download the document
  635 + $result = $this->doDownload($url);
  636 + $this->assertEqual($result['status'], 200, 'Status should be code 200 for success - '.$result['status']);
  637 + $this->assertEqual($result['error'], 0, 'Error code should be 0 for success - '.$result['error']);
  638 + $this->assertEqual($result['download'], $this->content, 'Document content should be the same as the original content of the initial upload');
  639 +
  640 + // ----------
  641 +
  642 + // Checkout base64 document
  643 + $result = $this->checkoutSmallDocument($documentId2);
  644 + $this->assertEqual($result->status_code, 0, 'Checkout base64 document - '.$result->message);
  645 + $checkoutBy = $result->checked_out_by;
  646 + $checkoutDate = $result->checked_out_date;
  647 + $content = $result->message;
  648 + $this->assertFalse(is_null($checkoutDate), 'Checked out date should not be null / empty - '.$checkoutDate);
  649 + $this->assertEqual($checkoutBy, 'Administrator', 'Using the Administrative user, checked out user must match - '.$checkoutBy);
  650 + $this->assertTrue(is_string($content), 'Base64 content should be a string');
  651 + $content = base64_decode($content);
  652 + $this->assertEqual($content, $this->content, 'Document content should be the same as that uploaded');
  653 +
  654 + // ----------
  655 +
  656 + // Checkin a new base64 version
  657 + $result = $this->checkinSmallDocument($documentId2, $filename2);
  658 + $this->assertEqual($result->status_code, 0, 'Checkin base64 document - '.$result->message);
  659 + $checkoutBy = $result->checked_out_by;
  660 + $this->assertTrue(empty($checkoutBy) || $checkoutBy == 'n/a', 'Document should no longer be checked out by anyone - '.$checkoutBy);
  661 +
  662 + // Download new version
  663 + $result = $this->downloadSmallDocument($documentId2);
  664 + $this->assertEqual($result->status_code, 0, 'Download checkedin base64 document - '.$result->message);
  665 + $content = $result->message;
  666 + $this->assertTrue(is_string($content), 'Content should be a string');
  667 + $content = base64_decode($content);
  668 + $this->assertEqual($content, $this->content_update, 'Document content should be the same as the updated content');
  669 +
  670 + // ----------
  671 +
  672 + // Get previous versions of the base64 document
  673 + $result = $this->getDocumentVersionHistory($documentId2);
  674 + $this->assertEqual($result->status_code, 0, 'Get document version history - '.$result->message);
  675 + $history = $result->history;
  676 + $this->assertTrue(is_array($history), 'Version history should be an array');
  677 + $this->assertEqual(count($history), 2, 'Version history should contain 2 items / versions');
  678 +
  679 + // Get the previous version number
  680 + $version = isset($history[1]) ? $history[1]->content_version : null;
  681 +
  682 + // Download previous version
  683 + $result = $this->downloadSmallDocument($documentId2, $version);
  684 + $this->assertEqual($result->status_code, 0, "Download previous version ($version) - ".$result->message);
  685 + $content = $result->message;
  686 + $this->assertTrue(is_string($content), 'Content should be a string');
  687 + $content = base64_decode($content);
  688 + $this->assertEqual($content, $this->content, 'Document content should be the same as the original content of the initial upload');
  689 +
  690 + // delete and cleanup
  691 + $this->deleteFolder($folderId);
  692 + }
  693 +
  694 + /**
  695 + * Tests getting and updating document metadata
  696 + */
  697 + public function testDocumentMetadata()
  698 + {
  699 + // Create folder containing the documents
  700 + $result = $this->createFolder(1, 'Test Metadata Container');
  701 + $this->assertEqual($result->status_code, 0, 'Create folder - '.$result->message);
  702 + $folderId = $result->id;
  703 +
  704 + // Upload document to folder
  705 + $filename = 'test_doc.txt';
  706 + $result = $this->createDocument($folderId, 'Test Doc', $filename);
  707 + $this->assertEqual($result->status_code, 0, 'Create document - '.$result->message);
  708 + $documentId = $result->document_id;
  709 + $this->assertTrue(is_numeric($documentId), 'Document id should be numeric');
  710 +
  711 + // get document metadata
  712 + $result = $this->getDocumentMetadata($documentId);
  713 + $this->assertEqual($result->status_code, 0, 'Get document metadata - '.$result->message);
  714 + $metadata = $result->metadata;
  715 + $this->assertTrue(is_array($metadata), 'Returned document metadata should be an array of fieldsets');
  716 +
  717 + // Add a new tag and a document author
  718 + foreach ($metadata as $fieldset){
  719 + $fields = $fieldset->fields;
  720 + switch($fieldset->fieldset){
  721 + case 'Tag Cloud':
  722 + $field_name = 'Tag';
  723 + $curr_val = 'n/a';
  724 + $new_val = 'unit test';
  725 + break;
  726 + case 'General information':
  727 + $field_name = 'Document Author';
  728 + $curr_val = 'n/a';
  729 + $new_val = 'Test Framework';
  730 + break;
  731 + }
  732 +
  733 + foreach ($fields as $field){
  734 + if($field->name == $field_name){
  735 + $this->assertEqual($field->value, $curr_val, "The current value of the given field, $field_name, should be \"$curr_val\"");
  736 + // update the value
  737 + $field->value = $new_val;
  738 + }
  739 + if($field->value == 'n/a'){
  740 + $field->value = '';
  741 + }
  742 + }
  743 + }
  744 +
  745 + // update metadata
  746 + $result = $this->updateDocumentMetadata($documentId, $metadata);
  747 +
  748 + // get metadata - ensure it matches the updated metadata
  749 + $result = $this->getDocumentMetadata($documentId);
  750 + $this->assertEqual($result->status_code, 0, 'Get document metadata - '.$result->message);
  751 + $metadata = $result->metadata;
  752 + $this->assertTrue(is_array($metadata), 'Returned document metadata should be an array of fieldsets');
  753 +
  754 + // Add a new tag and a document author
  755 + foreach ($metadata as $fieldset){
  756 + $fields = $fieldset->fields;
  757 + switch($fieldset->fieldset){
  758 + case 'Tag Cloud':
  759 + $field_name = 'Tag';
  760 + $curr_val = 'unit test';
  761 + break;
  762 + case 'General information':
  763 + $field_name = 'Document Author';
  764 + $curr_val = 'Test Framework';
  765 + break;
  766 + }
  767 +
  768 + foreach ($fields as $field){
  769 + if($field->name == $field_name){
  770 + $this->assertEqual($field->value, $curr_val, "The current value of the given field, $field_name, should be the same as the updated value: \"$curr_val\"");
  771 + }
  772 + }
  773 + }
  774 +
  775 + // Get previous versions of the document
  776 + $result = $this->getDocumentVersionHistory($documentId);
  777 + $this->assertEqual($result->status_code, 0, 'Get document version history - '.$result->message);
  778 + $history = $result->history;
  779 + $this->assertTrue(is_array($history), 'Version history should be an array');
  780 + $this->assertEqual(count($history), 2, 'Version history should contain 2 items / versions');
  781 +
  782 + // Get the previous version number
  783 + $version = isset($history[1]) ? $history[1]->metadata_version : null;
  784 +
  785 + // get document metadata for previous version
  786 + $result = $this->getDocumentMetadata($documentId, $version);
  787 + $this->assertEqual($result->status_code, 0, 'Get document metadata - '.$result->message);
  788 + $metadata = $result->metadata;
  789 + $this->assertTrue(is_array($metadata), 'Returned document metadata should be an array of fieldsets');
  790 +
  791 + // Add a new tag and a document author
  792 + foreach ($metadata as $fieldset){
  793 + $fields = $fieldset->fields;
  794 + switch($fieldset->fieldset){
  795 + case 'Tag Cloud':
  796 + $field_name = 'Tag';
  797 + $curr_val = 'n/a';
  798 + break;
  799 + case 'General information':
  800 + $field_name = 'Document Author';
  801 + $curr_val = 'n/a';
  802 + break;
  803 + }
  804 +
  805 + foreach ($fields as $field){
  806 + if($field->name == $field_name){
  807 + $this->assertEqual($field->value, $curr_val, "The current value of the given field, $field_name, should be the same as the previous version's value: \"$curr_val\"");
  808 + }
  809 + }
  810 + }
  811 +
  812 + // delete and cleanup
  813 + $this->deleteFolder($folderId);
  814 + }
  815 +
  816 + /**
  817 + * Test getting the contents of a folder
  818 + *
  819 + */
  820 + public function testGetFolderListing()
  821 + {
  822 + // create folder
  823 + $main_folder = 'Test Listing Container';
  824 + $result = $this->createFolder(1, $main_folder);
  825 + $this->assertEqual($result->status_code, 0, 'Create folder - '.$result->message);
  826 + $folderId = $result->id;
  827 +
  828 + // create subfolder 1
  829 + $sub_folder_name = 'Subfolder One';
  830 + $result = $this->createFolder($folderId, $sub_folder_name);
  831 + $this->assertEqual($result->status_code, 0, 'Create subfolder 1 - '.$result->message);
  832 + $subFolderId1 = $result->id;
  833 +
  834 + // create subfolder 2
  835 + $result = $this->createFolder($folderId, 'Subfolder Two');
  836 + $this->assertEqual($result->status_code, 0, 'Create subfolder 2 - '.$result->message);
  837 + $subFolderId2 = $result->id;
  838 +
  839 + // create subfolder 3 under subfolder 1
  840 + $result = $this->createFolder($subFolderId1, 'Subfolder Three');
  841 + $this->assertEqual($result->status_code, 0, 'Create subfolder 3 under subfolder 1 - '.$result->message);
  842 + $subFolderId3 = $result->id;
  843 +
  844 + // upload document into main folder
  845 + $filename = 'test_doc.txt';
  846 + $result = $this->createDocument($folderId, 'Test Doc', $filename);
  847 + $this->assertEqual($result->status_code, 0, 'Create document 1 in folder - '.$result->message);
  848 + $documentId = $result->document_id;
  849 + $this->assertTrue(is_numeric($documentId), 'Document id should be numeric');
  850 +
  851 + // upload document 2 into main folder
  852 + $filename2 = 'test_doc2.txt';
  853 + $result = $this->createDocument($folderId, 'Test Doc 2', $filename2);
  854 + $this->assertEqual($result->status_code, 0, 'Create document 1 in folder - '.$result->message);
  855 + $documentId2 = $result->document_id;
  856 + $this->assertTrue(is_numeric($documentId2), 'Document id should be numeric');
  857 +
  858 + // upload document 3 into subfolder 1
  859 + $filename3 = 'test_doc3.txt';
  860 + $result = $this->createDocument($subFolderId1, 'Test Doc 3', $filename3);
  861 + $this->assertEqual($result->status_code, 0, 'Create document 1 in sub folder 1 - '.$result->message);
  862 + $documentId3 = $result->document_id;
  863 + $this->assertTrue(is_numeric($documentId3), 'Document id should be numeric');
  864 +
  865 + // Get folder listing for folder 1 - folders only, depth of 1
  866 + $result = $this->getFolderContents($folderId, 1, 'F');
  867 + $this->assertEqual($result->status_code, 0, 'Get subfolders in folder - '.$result->message);
  868 + $folder_name = $result->folder_name;
  869 + $sub_folders = $result->items;
  870 + $this->assertEqual($folder_name, $main_folder, 'Folder name is - '.$folder_name);
  871 + $this->assertTrue(is_array($sub_folders), 'There should be an array of subfolders');
  872 + $this->assertEqual(count($sub_folders), 2, 'There should be 2 subfolders');
  873 +
  874 + // Get folder listing for folder 1 - folders and documents, infinite depth
  875 + $result = $this->getFolderContents($folderId, 5, 'FD');
  876 + $this->assertEqual($result->status_code, 0, 'Get all subfolders and documents under the folder - '.$result->message);
  877 + $items = $result->items;
  878 + $this->assertTrue(is_array($items), 'There should be an array of subfolders and documents');
  879 + $this->assertEqual(count($items), 4, 'There should be 2 subfolders and 2 documents in the immediate folder');
  880 +
  881 + // Loop through items, find sub folder 1
  882 + $docs = 0;
  883 + $folders = 0;
  884 + foreach ($items as $item){
  885 + // increment count of item type
  886 + $folders = ($item->item_type == 'F') ? $folders + 1 : $folders;
  887 + $docs = ($item->item_type == 'D') ? $docs + 1 : $docs;
  888 +
  889 + if($item->id == $subFolderId1){
  890 + $sub_items = $item->items;
  891 +
  892 + $this->assertTrue(is_array($sub_items), 'Subfolder 1 should contain an array of contents');
  893 + $this->assertEqual(count($sub_items), 2, 'Subfolder 1 should contain a folder and document');
  894 +
  895 + }
  896 + }
  897 +
  898 + $this->assertEqual($folders, 2, 'There should be 2 folders');
  899 + $this->assertEqual($docs, 2, 'There should be 2 documents');
  900 +
  901 + // Get folder listing for subfolder 1 - documents only, depth of 1
  902 + $result = $this->getFolderContents($subFolderId1, 1, 'D');
  903 + $this->assertEqual($result->status_code, 0, 'Get documents under subfolder 1 - '.$result->message);
  904 + $folder_name = $result->folder_name;
  905 + $items = $result->items;
  906 + $this->assertEqual($folder_name, $sub_folder_name, 'Subfolder name is - '.$folder_name);
  907 + $this->assertTrue(is_array($items), 'There should be an array of documents');
  908 + $this->assertEqual(count($items), 1, 'There should be 1 document');
  909 +
  910 + // delete and cleanup
  911 + $this->deleteFolder($folderId);
  912 + }
264 } 913 }
265 ?> 914 ?>
266 \ No newline at end of file 915 \ No newline at end of file
thirdpartyjs/jquery/plugins/selectimage/css/selectimage.css 0 โ†’ 100644
  1 +#selectimage_container img {
  2 + cursor: pointer;
  3 + text-decoration: none;
  4 + border: 10px solid white;
  5 +}
  6 +
  7 +#selectimage_container img:hover {
  8 + text-decoration: none;
  9 + border: 10px solid white;
  10 +}
  11 +
  12 +.jq_select_image {
  13 + float: left;
  14 + border: 1px solid #cccccc;
  15 + margin-right: 5px;
  16 + padding: 0px;
  17 + display:inline;
  18 + height:70px;
  19 +}
  20 +
  21 +.selectimage_border_background {
  22 + border: 10px solid white;
  23 +}
  24 +
  25 +.selectimage_border_hover {
  26 + border: 10px solid #9c9c9c;
  27 +}
  28 +
  29 +.selectimage_border_click {
  30 + border: 10px solid #f2943a;
  31 +}
0 \ No newline at end of file 32 \ No newline at end of file
thirdpartyjs/jquery/plugins/selectimage/jquery.selectimage.js 0 โ†’ 100755
  1 +/**
  2 + * jQuery Select Image Plugin
  3 + *
  4 + * @author Charl Mert <charl@knowledgetree.com>
  5 + *
  6 + * KnowledgeTree Community Edition
  7 + * Document Management Made Simple
  8 + * Copyright (C) 2009, 2010 KnowledgeTree Inc.
  9 + *
  10 + * This program is free software; you can redistribute it and/or modify it under
  11 + * the terms of the GNU General Public License version 3 as published by the
  12 + * Free Software Foundation.
  13 + *
  14 + * This program is distributed in the hope that it will be useful, but WITHOUT
  15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17 + * details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  23 + * California 94120-7775, or email info@knowledgetree.com.
  24 + *
  25 + * The interactive user interfaces in modified source and object code versions
  26 + * of this program must display Appropriate Legal Notices, as required under
  27 + * Section 5 of the GNU General Public License version 3.
  28 + *
  29 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  30 + * these Appropriate Legal Notices must retain the display of the "Powered by
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * copyright notice.
  35 + * Contributor( s): ______________________________________
  36 + */
  37 +
  38 +jQuery.fn.selectImage = function() {
  39 + return this.each(function(){
  40 +
  41 + var opt = jQuery.extend({
  42 + passBackNamespace : 'selectimage', //TODO: Let plugin detect parent form and produce the hidden inputs. For now the user has to place the predefined hidden inputs onto the form manually.
  43 + multiselect : false,
  44 + hover : '#e2e2e2',
  45 + click : '#f2943a', //Orange
  46 + background : 'white',
  47 + selected : ''
  48 + }, opt);
  49 +
  50 + var containerId = this.id;
  51 + var custId = 0;
  52 +
  53 + //Setting up border
  54 + jQuery('#' + containerId + ' img' ).css('border', '10px solid ' + opt.background);
  55 +
  56 + jQuery('#' + containerId + ' img').each(function(){
  57 + //Assigning custom id's to attach event handlers to
  58 + if (this.id == '') {
  59 + this.id = 'select_image_img_' + custId;
  60 + custId++;
  61 + }
  62 +
  63 + var toggle = 1;
  64 +
  65 + //Click to select
  66 + jQuery('#' + this.id).click(function(){
  67 + opt.selected = this.id;
  68 + jQuery('#' + opt.passBackNamespace + '_src').val(this.src);
  69 + jQuery('#' + opt.passBackNamespace + '_alt').val(this.alt);
  70 + jQuery('#' + opt.passBackNamespace + '_title').val(this.title);
  71 +
  72 + //Resetting background:
  73 + jQuery('#' + containerId + ' img' ).css('border', '10px solid ' + opt.background);
  74 + jQuery('#' + this.id).css('border', '10px solid ' + opt.click);
  75 + })
  76 +
  77 + //Hover Effect
  78 + jQuery('#' + this.id).mouseenter(function(){
  79 + if (this.id != opt.selected) {
  80 + jQuery('#' + this.id).css('border', '10px solid ' + opt.hover).show("slow");
  81 + }
  82 + })
  83 +
  84 + jQuery('#' + this.id).mouseleave(function(){
  85 + if (this.id != opt.selected) {
  86 + jQuery('#' + this.id).css('border', '10px solid ' + opt.background).show("slow");
  87 + }
  88 + })
  89 +
  90 + });
  91 + });
  92 +};
  93 +
  94 +jQuery.log = function(message) {
  95 + if(window.console) {
  96 + console.debug(message);
  97 + } else {
  98 + alert(message);
  99 + }
  100 +};
0 \ No newline at end of file 101 \ No newline at end of file