Commit 8dc89ab8c7395e7275d52ea504779386f96ca35d

Authored by kevin_fourie
1 parent cd0a813c

Merged in from DEV trunk...

KTS-2520
"Fatal Error when deleting a state in a workflow and selecting a replacement state."
Fixed. Corrected cache clearing function call.

Committed By: Kevin Fourie
Reviewed By: Conrad Vermeulen 

WSA-55
"Allow users to be able to update the 'creator', 'created date', and other system fields via the KTAPI and web services"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

WSA-57
"Checkout functions should return document detail"
Updated.

WSA-56
"rename document_detail.updated fields to be document_detail.modified to be consistent with normal interface"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

WSA-58
"All functions working with documents should return document_detail structure. This allows for less chipy based communication"
Fixed.

WSA-57
"Checkout functions should return document detail"
Fixed. WSA-58 covers this too.

WSA-59
"Log incoming SOAP requests and outgoing responses based on the debug level"
Fixed.

WSA-55
"Allow users to be able to update the 'creator', 'created date', and other system fields via the KTAPI and web services"
Updated. update_document_metadata allows for parameters to be passed.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

WSA-59
"Log incoming SOAP requests and outgoing responses based on the debug level"
Deleted. Proxy not needed anymore.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

Reverted commit of "Forgot Password" functionality. It's still DEV.

Committed By: Kevin Fourie
Reviewed By: Jalaloedien Abrahams

KTS-2683
"Bug with AnyMetadata search field as it does not pick up on metadata"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2647
"Folder utilisation dashlet should get the indexer location from the indexer and not from the config.ini"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2641
"indexing task should log start and stop as debug"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2639
"index optimisation task outputs name and indication when done"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2638
"index migration task should log start and stop as debug"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-1112
"after auto log-out, re-login as different user gives old url"

Fixed.
Added a check to redirect to the dashboard if a different user logs back in after a logout or a timeout.

Committed By: Jonathan Byrne
Reviewed By: Jalaloedien Abrahams

KTS-2672
"KTWebDAV move functions fail on litmus"
Fixed. Corrected status messages. Adjusted rename to check for overwrite.

KTS-2671
"KTWebDAV copy functions fail on litmus"
Fixed. Corrected status messages. Added extra depth of '0'. Changed documentutil to accept a new document or folder name. Changed folderutil to allow a copy of only the folder, ignoring all subfolders and documents.

BBS-1119
"Refactor move functions into ktapi"
In progress. Cleaned up some functionality. Added in line documentation.

BBS-1118
"Refactor copy functions into ktapi"
In progress. Added in line documentation.

KTS-2643
"basic tasks called by scheduler need to be in the source install"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Megan Watson

KTS-2687
"update the db install/upgrade scripts so that the php scripts that must be scheduled are referenced correctly"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Megan Watson

KTS-2690
"Strange character in search_ranking table. This may impact on ranking of search criteria."
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Megan Watson

KTS-2688
"Index migration script should stop running when complete so script is not called unnecessarily"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Megan Watson

KTS-2575
"df.exe cannot be found by the Disk Usage dashlet"
Fixed.

Contributed By: Tahir Tahang
Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-1390
"A more precise error message needed when creating a duplicate of an already existing Permission"

Fixed
Added a more detailed error message system.

Committed By: Jonathan Byrne
Reviewed By: Kevin Fourie

KTS-2697
"'between' operator is not working in the advanced search query builder"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Jalaloedien Abrahams

KTS-2452
"Re-evaluate the placement, size and icon for the download icon"

Fixed
Changed download icon.

Committed By: Jonathan Byrne
Reviewed By: Kevin Fourie

WSA-31
"copy_document seems to return an exception in c# even though it was successful."
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-1820
"Reachable folders being considered orphaned folders"
Fixed. Added a check for folder details permission in addition to the check on read permission, in getBrowseableFolders().

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen

KTS-2600
"Document Indexer Statistics Dashlet - improve text / US spelling / Capitalization / Link to Management Page"
Updated. Dashlet text was improved.Also a image toggle has been added for the notes.

Committed By:Yusuf Davids
Reviewed By:Jalaloedien Abrahams

KTS-2488
"Improve database incompatibility error message"
Fixed. Error message changed.

Committed By:Yusuf Davids
Reviewed By:Jalaloedien Abrahams

KTS-2488
"Improve database incompatibility error message"
Fixed. Error message changed.

Committed By:Yusuf Davids
Reviewed By:Jalaloedien Abrahams

KTS-2641
"indexing task should log start and stop as debug"
Updated. Static function should not have $this

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

WSA-63
"add add_document_with_metadata and checkin_document_with_metadata to webservice"
Added.

WSA-64
"Refactor the nunit tests a little"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2705
"Comment length not being calculated properly in the Delete, Move, Archive, Check in, Check out comment fields."

Fixed
Both normal and utf-8 character sets lengths should be calculated correctly now.

Committed By: Jonathan Byrne
Reviewed By: Jalaloedien Abrahams

KTS-2505
"Database configuration issues cause horrible knowledgetree failure"

Fixed
Added a check to stop any database calls in search if there is a database error.

Committed By: Jonathan Byrne
Reviewed By: Jalaloedien Abrahams

KTS-2376
"When uploading .PNG image files these are incorrectly displayed as JPEG images"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Megan Watson

WSA-65
"Remove php5 specific modifiers on functions so that web services works on both 3.4.x and 3.5.x"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Martin Kirsten




git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@7698 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 51 changed files with 2304 additions and 1042 deletions
bin/scheduler.php
... ... @@ -88,20 +88,20 @@ function calculateRunTime($sFreq, $iTime) {
88 88 }
89 89  
90 90 // Update the task information in the database
91   -function updateTask($sTable, $aFieldValues, $iId) {
92   - DBUtil::autoUpdate($sTable, $aFieldValues, $iId);
  91 +function updateTask($aFieldValues, $iId) {
  92 + DBUtil::autoUpdate('scheduler_tasks', $aFieldValues, $iId);
93 93 }
94 94  
95 95 // Get the list of tasks due to be run from the database
96   -function getTaskList($sTable) {
  96 +function getTaskList() {
97 97 $now = date('Y-m-d H:i:s'); //time();
98   - $query = "SELECT * FROM {$sTable}
99   - WHERE is_complete = 0 AND run_time < '{$now}'";
  98 +
  99 + $query = "SELECT * FROM scheduler_tasks WHERE is_complete = 0 AND run_time < '{$now}'";
100 100  
101 101 $result = DBUtil::getResultArray($query);
102 102  
103 103 if (PEAR::isError($result)){
104   - exit();
  104 + return false;
105 105 }
106 106 return $result;
107 107 }
... ... @@ -109,16 +109,22 @@ function getTaskList($sTable) {
109 109  
110 110 /* ** Scheduler script ** */
111 111  
112   -$sTable = 'scheduler_tasks';
  112 +global $default;
113 113  
114   -// Get task list
115   -$aList = getTaskList($sTable);
  114 +$default->log->debug('Scheduler: starting');
116 115  
117   -global $default;
  116 +// Get task list
  117 +$aList = getTaskList();
  118 +if (empty($aList))
  119 +{
  120 + $default->log->debug('Scheduler: stopping - nothing to do');
  121 + return;
  122 +}
118 123  
119 124 // Loop through tasks and run
120   -if(!empty($aList)){
121   - foreach($aList as $item){
  125 +
  126 + foreach($aList as $item)
  127 + {
122 128 $aUpdate = array();
123 129 $iEnd = 0; $iStart = 0; $iDuration = 0;
124 130 $sFreq = ''; $sParameters = '';
... ... @@ -132,64 +138,84 @@ if(!empty($aList)){
132 138 $sParameters = $item['script_params'];
133 139  
134 140 // Check if script is windows or *nix compatible
135   - $extArr = explode('.', $sTaskUrl);
136   - $ext = array_pop($extArr);
137   - $script = implode('.', $extArr);
138   - if(OS_WINDOWS){
139   - switch($ext){
140   - case 'sh':
141   - $sTaskUrl = $script.'.bat';
142   - break;
143   - case 'bin':
144   - $sTaskUrl = $script.'.exe';
145   - break;
146   - }
147   - }else{
148   - switch($ext){
149   - case 'bat':
150   - if(file_exists(KT_DIR . $script.'.sh')){
151   - $sTaskUrl = $script.'.sh';
152   - break;
153   - }
154   - // File doesn't exist - log error
155   - $default->log->error("Scheduler: Task script can't be found at ".KT_DIR."{$script}.sh");
156   - continue;
157   - break;
158   - case 'exe':
159   - if(file_exists(KT_DIR . $script)){
160   - $sTaskUrl = $script;
161   - break;
162   - }
163   - if(file_exists(KT_DIR . $script.'.bin')){
164   - $sTaskUrl = $script.'.bin';
165   - break;
166   - }
167   - // File doesn't exist - log error
168   - $default->log->error("Scheduler: Task script can't be found at ".KT_DIR."{$script} or ".KT_DIR."{$script}.bin");
169   - continue;
170   - break;
171   - }
  141 + $ext = pathinfo($sTaskUrl, PATHINFO_EXTENSION);
  142 + $script = substr($sTaskUrl,0,-strlen($ext)-1);
  143 +
  144 + if(OS_WINDOWS)
  145 + {
  146 + $mapping = array('sh'=>'bin','bat'=>'exe');
  147 + if (array_key_exists($ext, $mapping))
  148 + {
  149 + $sTaskUrl = $script . '.' . $mapping[$ext];
  150 + }
  151 + }
  152 + else
  153 + {
  154 + $mapping = array('bat'=>'sh', 'exe'=>'bin');
  155 +
  156 + if (array_key_exists($ext, $mapping))
  157 + {
  158 + switch ($ext)
  159 + {
  160 + case 'exe':
  161 + if (is_executable(KT_DIR . '/' . $script))
  162 + {
  163 + $sTaskUrl = $script;
  164 + break;
  165 + }
  166 + default:
  167 + $sTaskUrl = $script . '.' . $mapping[$ext];
  168 + }
  169 + }
  170 +
  171 + if (!is_executable(KT_DIR . '/' . $script) && $ext != 'php')
  172 + {
  173 + $default->log->error("Scheduler: The script '{$sTaskUrl}' is not executable.");
  174 + continue;
  175 + }
  176 + }
  177 +
  178 + $file = realpath(KT_DIR . '/' . $sTaskUrl);
  179 +
  180 + if ($file === false)
  181 + {
  182 + $default->log->error("Scheduler: The script '{$sTaskUrl}' cannot be resolved.");
  183 + continue;
172 184 }
173 185  
174 186 $iTime = time();
175   - $iStart = explode(' ', microtime());
  187 + $iStart = KTUtil::getBenchmarkTime();
176 188  
177 189 // Run the script
178   - $file = realpath(KT_DIR . '/' . $sTaskUrl);
179 190  
180 191 $cmd = "\"$file\" {$sParameters}";
181 192  
182   - $start = KTUtil::getBenchmarkTime();
  193 + if ($ext == 'php')
  194 + {
  195 + $config = KTConfig::getSingleton();
  196 + $phpPath = $config->get('externalBinary/php');
  197 +
  198 + // being protective as some scripts work on relative paths
  199 + $dirname = dirname($file);
  200 + chdir($dirname);
  201 +
  202 + $cmd = "$phpPath $cmd";
  203 + }
  204 +
183 205 if (OS_WINDOWS)
184 206 {
185 207 $cmd = str_replace( '/','\\',$cmd);
186   - $res = `"$cmd" 2>&1`;
  208 + $res = `$cmd`;
187 209 }
188 210 else
189 211 {
190 212 $res = shell_exec($cmd." 2>&1");
191 213 }
192 214  
  215 + // On completion - reset run time
  216 + $iEnd = KTUtil::getBenchmarkTime();
  217 + $iDuration = number_format($iEnd - $iStart,2);
  218 +
193 219 if (!empty($res))
194 220 {
195 221 $default->log->info("Scheduler - Task: $sTask");
... ... @@ -199,37 +225,26 @@ if(!empty($aList)){
199 225 }
200 226 else
201 227 {
202   - $time = number_format(KTUtil::getBenchmarkTime() - $start,2,'.',',');
203   - $default->log->debug("Scheduler - Task: {$sTask} completed in {$diff}s.");
  228 + $default->log->debug("Scheduler - Task: {$sTask} completed in {$iDuration}s.");
204 229 }
205 230  
206   -
207   - // On completion - reset run time
208   - $iEnd = explode(' ', microtime());
209   - $iDuration = ($iEnd[1] + $iEnd[0]) - ($iStart[1] + $iStart[0]);
210   - $iDuration = round($iDuration, 3);
211   -
212   - if(($sFreq == 'once' || empty($sFreq)) && $retval !== FALSE){
  231 + if(($sFreq == 'once' || empty($sFreq)) && $retval !== FALSE)
  232 + {
213 233 // Set is_complete to true
214 234 $aUpdate['is_complete'] = '1';
215   - }else{
  235 + }
  236 + else
  237 + {
216 238 $iNextTime = calculateRunTime($sFreq, $iTime);
217 239 $aUpdate['run_time'] = date('Y-m-d H:i:s', $iNextTime);
218 240 }
  241 +
219 242 $aUpdate['previous_run_time'] = date('Y-m-d H:i:s', $iTime);
220 243 $aUpdate['run_duration'] = $iDuration;
221 244  
222   - updateTask($sTable, $aUpdate, $item['id']);
223   -
224   - // clear parameters
225   - if(!empty($aParams)){
226   - foreach($aParams as $param){
227   - $aParam = explode('=', $param);
228   - $$aParam[0] = '';
229   - }
230   - $aParam = array();
231   - $aParams = array();
232   - }
  245 + updateTask($aUpdate, $item['id']);
233 246 }
234   -}
  247 +
  248 +$default->log->debug('Scheduler: stopping');
  249 +
235 250 ?>
236 251 \ No newline at end of file
... ...
control.php
1 1 <?php
2 2 /*
3   - * $Id:$
  3 + * $Id$
4 4 *
5 5 * KnowledgeTree Open Source Edition
6 6 * Document Management Made Simple
... ... @@ -81,6 +81,8 @@ if ($action != &#39;login&#39;) {
81 81 }
82 82 if (PEAR::isError($ret)) {
83 83 $url = $url . '&errorMessage=' . urlencode($ret->getMessage());
  84 + session_start();
  85 + $_SESSION['errormessage']['login'] = $ret->getMessage();
84 86 }
85 87 redirect($url);
86 88 exit(0);
... ...
i18n/knowledgeTree.pot
... ... @@ -4062,8 +4062,32 @@ msgstr &quot;&quot;
4062 4062 msgid "Error creating allocation"
4063 4063 msgstr ""
4064 4064  
4065   -#: plugins/ktcore/admin/managePermissions.php:76
4066   -msgid "Error creating permission"
  4065 +#: plugins/ktcore/admin/managePermissions.php:81
  4066 +msgid "An error occured while creating your permission"
  4067 +msgstr ""
  4068 +
  4069 +#: plugins/ktcore/admin/managePermissions.php:86
  4070 +msgid "An error occured while creating your permission: The System Name was not provided."
  4071 +msgstr ""
  4072 +
  4073 +#: plugins/ktcore/admin/managePermissions.php:92
  4074 +msgid "An error occured while creating your permission: The Display Name was not provided."
  4075 +msgstr ""
  4076 +
  4077 +#: plugins/ktcore/admin/managePermissions.php:98
  4078 +msgid "An error occured while creating your permission: The Display Name and System Name weren't provided."
  4079 +msgstr ""
  4080 +
  4081 +#: plugins/ktcore/admin/managePermissions.php:120
  4082 +msgid "An error occured while creating your permission: The Display Name and System Name you have provided both already exist."
  4083 +msgstr ""
  4084 +
  4085 +#: plugins/ktcore/admin/managePermissions.php:129
  4086 +msgid "An error occured while creating your permission: A permission with the same System Name already exists."
  4087 +msgstr ""
  4088 +
  4089 +#: plugins/ktcore/admin/managePermissions.php:138
  4090 +msgid "An error occured while creating your permission: A permission with the same Display Name already exists."
4067 4091 msgstr ""
4068 4092  
4069 4093 #: plugins/ktcore/admin/managePermissions.php:95
... ...
ktapi/KTAPIDocument.inc.php
... ... @@ -5,32 +5,32 @@
5 5 * KnowledgeTree Open Source Edition
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
8   - *
  8 + *
9 9 * This program is free software; you can redistribute it and/or modify it under
10 10 * the terms of the GNU General Public License version 3 as published by the
11 11 * Free Software Foundation.
12   - *
  12 + *
13 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 16 * details.
17   - *
  17 + *
18 18 * You should have received a copy of the GNU General Public License
19 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20   - *
  20 + *
21 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23   - *
  23 + *
24 24 * The interactive user interfaces in modified source and object code versions
25 25 * of this program must display Appropriate Legal Notices, as required under
26 26 * Section 5 of the GNU General Public License version 3.
27   - *
  27 + *
28 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 29 * these Appropriate Legal Notices must retain the display of the "Powered by
30   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  30 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
31 31 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
32   - * must display the words "Powered by KnowledgeTree" and retain the original
33   - * copyright notice.
  32 + * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * copyright notice.
34 34 * Contributor( s): ______________________________________
35 35 *
36 36 */
... ... @@ -314,13 +314,16 @@ class KTAPI_Document extends KTAPI_FolderItem
314 314 {
315 315 continue;
316 316 }
  317 +
  318 +
  319 +
317 320 $result[] = array(
318 321 'document_id'=>(int)$row['document_id'],
319 322 'title'=> $row['title'],
320 323 'size'=>(int)$row['size'],
321   - 'workflow'=>$row['workflow'],
322   - 'workflow_state'=>$row['workflow_state'],
323   - 'link_type'=>$row['link_type'],
  324 + 'workflow'=>empty($row['workflow'])?'n/a':$row['workflow'],
  325 + 'workflow_state'=>empty($row['workflow_state'])?'n/a':$row['workflow_state'],
  326 + 'link_type'=>empty($row['link_type'])?'unknown':$row['link_type'],
324 327 );
325 328 }
326 329  
... ... @@ -447,6 +450,7 @@ class KTAPI_Document extends KTAPI_FolderItem
447 450 * @param string $reason
448 451 * @param string $newname
449 452 * @param string $newfilename
  453 + * @return KTAPI_Document
450 454 */
451 455 function copy(&$ktapi_target_folder, $reason, $newname=null, $newfilename=null)
452 456 {
... ... @@ -533,12 +537,14 @@ class KTAPI_Document extends KTAPI_FolderItem
533 537 $oTrigger = new $sTrigger;
534 538 $aInfo = array(
535 539 'document' => $new_document,
536   - 'old_folder' => $this->folder->get_folder(),
  540 + 'old_folder' => $this->ktapi_folder->get_folder(),
537 541 'new_folder' => $target_folder,
538 542 );
539 543 $oTrigger->setInfo($aInfo);
540 544 $ret = $oTrigger->postValidate();
541 545 }
  546 +
  547 + return KTAPI_Document::get($this->ktapi, $new_document->getId());
542 548 }
543 549  
544 550 /**
... ... @@ -676,6 +682,10 @@ class KTAPI_Document extends KTAPI_FolderItem
676 682 }
677 683  
678 684 $doctypeid = KTAPI::get_documenttypeid($documenttype);
  685 + if (PEAR::isError($doctypeid))
  686 + {
  687 + return $doctypeid;
  688 + }
679 689  
680 690 if ($this->document->getDocumentTypeId() != $doctypeid)
681 691 {
... ... @@ -836,7 +846,7 @@ class KTAPI_Document extends KTAPI_FolderItem
836 846 }
837 847  
838 848 $workflowid=$this->document->getWorkflowId();
839   - if (!empty($workflowid))
  849 + if (empty($workflowid))
840 850 {
841 851 return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS);
842 852 }
... ... @@ -1045,6 +1055,11 @@ class KTAPI_Document extends KTAPI_FolderItem
1045 1055 function update_metadata($metadata)
1046 1056 {
1047 1057 global $default;
  1058 + if (empty($metadata))
  1059 + {
  1060 + return;
  1061 + }
  1062 +
1048 1063 $packed = $this->get_packed_metadata($metadata);
1049 1064  
1050 1065 DBUtil::startTransaction();
... ... @@ -1079,6 +1094,233 @@ class KTAPI_Document extends KTAPI_FolderItem
1079 1094  
1080 1095 }
1081 1096  
  1097 + /**
  1098 + * This updates the system metadata on the document.
  1099 + *
  1100 + * @param array $sysdata
  1101 + */
  1102 + function update_sysdata($sysdata)
  1103 + {
  1104 + if (empty($sysdata))
  1105 + {
  1106 + return;
  1107 + }
  1108 + $owner_mapping = array(
  1109 + 'created_by'=>'creator_id',
  1110 + 'modified_by'=>'modified_user_id',
  1111 + 'owner'=>'owner_id'
  1112 + );
  1113 +
  1114 + $documents = array();
  1115 + $document_content = array();
  1116 +
  1117 + foreach($sysdata as $rec)
  1118 + {
  1119 + if (is_object($rec))
  1120 + {
  1121 + $name = $rec->name;
  1122 + $value = sanitizeForSQL($rec->value);
  1123 + }
  1124 + elseif(is_array($rec))
  1125 + {
  1126 + $name = $rec['name'];
  1127 + $value = sanitizeForSQL($rec['value']);
  1128 + }
  1129 + else
  1130 + {
  1131 + // just ignore
  1132 + continue;
  1133 + }
  1134 + switch($name)
  1135 + {
  1136 + case 'created_date':
  1137 + $documents['created'] = $value;
  1138 + break;
  1139 + case 'modified_date':
  1140 + $documents['modified'] = $value;
  1141 + break;
  1142 + case 'is_immutable':
  1143 + $documents['immutable'] = in_array(strtolower($value), array('1','true','on','yes'))?'1':'0';
  1144 + break;
  1145 + case 'filename':
  1146 + $document_content['filename'] = $value;
  1147 + break;
  1148 + case 'major_version':
  1149 + $document_content['major_version'] = $value;
  1150 + break;
  1151 + case 'minor_version':
  1152 + $document_content['minor_version'] = $value;
  1153 + break;
  1154 + case 'version':
  1155 + $version = number_format($value + 0,5);
  1156 + list($major_version, $minor_version) = explode('.', $version);
  1157 + $document_content['major_version'] = $major_version;
  1158 + $document_content['minor_version'] = $minor_version;
  1159 + break;
  1160 + case 'mime_type':
  1161 + $sql = "select id from mime_types where mimetypes='$value'";
  1162 + $value = DBUtil::getResultArray($sql);
  1163 + if (PEAR::isError($value))
  1164 + {
  1165 + return $value;
  1166 + }
  1167 + if (count($value) == 0)
  1168 + {
  1169 + break;
  1170 + }
  1171 + $value = $value[0]['id'];
  1172 + $document_content['mime_id'] = $value;
  1173 + break;
  1174 + case 'owner':
  1175 + case 'created_by':
  1176 + case 'modified_by':
  1177 + $sql = "select id from users where name='$value'";
  1178 + $userId = DBUtil::getResultArray($sql);
  1179 + if (PEAR::isError($userId))
  1180 + {
  1181 + return $userId;
  1182 + }
  1183 + if (empty($userId))
  1184 + {
  1185 + $sql = "select id from users where username='$value'";
  1186 + $userId = DBUtil::getResultArray($sql);
  1187 + if (PEAR::isError($userId))
  1188 + {
  1189 + return $userId;
  1190 + }
  1191 + }
  1192 + if (empty($userId))
  1193 + {
  1194 + // if not found, not much we can do
  1195 + break;
  1196 + }
  1197 + $userId=$userId[0];
  1198 + $userId=$userId['id'];
  1199 +
  1200 + $name = $owner_mapping[$name];
  1201 + $documents[$name] = $userId;
  1202 + break;
  1203 + default:
  1204 + // TODO: we should do some logging
  1205 + //return new PEAR_Error('Unexpected field: ' . $name);
  1206 + }
  1207 + }
  1208 +
  1209 + if (count($documents) > 0)
  1210 + {
  1211 + $sql = "UPDATE documents SET ";
  1212 + $i=0;
  1213 + foreach($documents as $name=>$value)
  1214 + {
  1215 + if ($i++ > 0) $sql .= ",";
  1216 + if (is_numeric($value))
  1217 + $sql .= "$name=$value";
  1218 + else
  1219 + $sql .= "$name='$value'";
  1220 + }
  1221 + $sql .= " WHERE id=$this->documentid";
  1222 + $result = DBUtil::runQuery($sql);
  1223 + if (PEAR::isError($result))
  1224 + {
  1225 + return $result;
  1226 + }
  1227 + }
  1228 + if (count($document_content) > 0)
  1229 + {
  1230 + $content_id = $this->document->getContentVersionId();
  1231 + $sql = "UPDATE document_content_version SET ";
  1232 + $i=0;
  1233 + foreach($document_content as $name=>$value)
  1234 + {
  1235 + if ($i++ > 0) $sql .= ",";
  1236 + $sql .= "$name='$value'";
  1237 + }
  1238 + $sql .= " WHERE id=$content_id";
  1239 + $result = DBUtil::runQuery($sql);
  1240 + if (PEAR::isError($result))
  1241 + {
  1242 + return $result;
  1243 + }
  1244 + }
  1245 + }
  1246 +
  1247 + function clearCache()
  1248 + {
  1249 + // TODO: we should only clear the cache for the document we are working on
  1250 + // this is a quick fix but not optimal!!
  1251 +
  1252 +
  1253 + $metadataid = $this->document->getMetadataVersionId();
  1254 + $contentid = $this->document->getContentVersionId();
  1255 +
  1256 + $cache = KTCache::getSingleton();
  1257 +
  1258 + $cache->remove('KTDocumentMetadataVersion/id', $metadataid);
  1259 + $cache->remove('KTDocumentContentVersion/id', $contentid);
  1260 + $cache->remove('KTDocumentCore/id', $this->documentid);
  1261 + $cache->remove('Document/id', $this->documentid);
  1262 + unset($GLOBALS['_OBJECTCACHE']['KTDocumentMetadataVersion'][$metadataid]);
  1263 + unset($GLOBALS['_OBJECTCACHE']['KTDocumentContentVersion'][$contentid]);
  1264 + unset($GLOBALS['_OBJECTCACHE']['KTDocumentCore'][$this->documentid]);
  1265 +
  1266 + $this->document = &Document::get($this->documentid);
  1267 + }
  1268 +
  1269 + function mergeWithLastMetadataVersion()
  1270 + {
  1271 + // keep latest metadata version
  1272 + $metadata_version = $this->document->getMetadataVersion();
  1273 + if ($metadata_version == 0)
  1274 + {
  1275 + // this could theoretically happen in the case we are updating metadata and sysdata, but no metadata fields are specified.
  1276 + return;
  1277 + }
  1278 +
  1279 + $metadata_id = $this->document->getMetadataVersionId();
  1280 +
  1281 + // get previous version
  1282 + $sql = "SELECT id, metadata_version FROM document_metadata_version WHERE id<$metadata_id AND document_id=$this->documentid order by id desc";
  1283 + $old = DBUtil::getResultArray($sql);
  1284 + if (is_null($old) || PEAR::isError($old))
  1285 + {
  1286 + return new PEAR_Error('Previous version could not be resolved');
  1287 + }
  1288 + // only interested in the first one
  1289 + $old=$old[0];
  1290 + $old_metadata_id = $old['id'];
  1291 + $old_metadata_version = $old['metadata_version'];
  1292 +
  1293 + DBUtil::startTransaction();
  1294 +
  1295 + // delete previous metadata version
  1296 +
  1297 + $sql = "DELETE FROM document_metadata_version WHERE id=$old_metadata_id";
  1298 + $rs = DBUtil::runQuery($sql);
  1299 + if (PEAR::isError($rs))
  1300 + {
  1301 + DBUtil::rollback();
  1302 + return $rs;
  1303 + }
  1304 +
  1305 + // make latest equal to previous
  1306 + $sql = "UPDATE document_metadata_version SET metadata_version=$old_metadata_version WHERE id=$metadata_id";
  1307 + $rs = DBUtil::runQuery($sql);
  1308 + if (PEAR::isError($rs))
  1309 + {
  1310 + DBUtil::rollback();
  1311 + return $rs;
  1312 + }
  1313 + $sql = "UPDATE documents SET metadata_version=$old_metadata_version WHERE id=$this->documentid";
  1314 + $rs = DBUtil::runQuery($sql);
  1315 + if (PEAR::isError($rs))
  1316 + {
  1317 + DBUtil::rollback();
  1318 + return $rs;
  1319 + }
  1320 + DBUtil::commit();
  1321 +
  1322 + $this->clearCache();
  1323 + }
1082 1324  
1083 1325 /**
1084 1326 * This returns a workflow transition
... ... @@ -1156,6 +1398,10 @@ class KTAPI_Document extends KTAPI_FolderItem
1156 1398 */
1157 1399 function get_detail()
1158 1400 {
  1401 + global $default;
  1402 + // make sure we ge tthe latest
  1403 + $this->clearCache();
  1404 +
1159 1405 $detail = array();
1160 1406 $document = $this->document;
1161 1407  
... ... @@ -1191,6 +1437,7 @@ class KTAPI_Document extends KTAPI_FolderItem
1191 1437 }
1192 1438 $detail['created_by'] = $username;
1193 1439 $detail['updated_date'] = $document->getLastModifiedDate();
  1440 + $detail['modified_date'] = $document->getLastModifiedDate();
1194 1441  
1195 1442 $userid = $document->getModifiedUserId();
1196 1443 if (is_numeric($userid))
... ... @@ -1202,6 +1449,7 @@ class KTAPI_Document extends KTAPI_FolderItem
1202 1449 {
1203 1450 $username='n/a';
1204 1451 }
  1452 + $detail['modified_by'] = $username;
1205 1453 $detail['updated_by'] = $username;
1206 1454 $detail['document_id'] = (int) $document->getId();
1207 1455 $detail['folder_id'] = (int) $document->getFolderID();
... ... @@ -1230,6 +1478,22 @@ class KTAPI_Document extends KTAPI_FolderItem
1230 1478 }
1231 1479 $detail['workflow_state']=$workflowstate;
1232 1480  
  1481 + $userid = $document->getOwnerID();
  1482 +
  1483 + if (is_numeric($userid))
  1484 + {
  1485 + $user = User::get($userid);
  1486 + $username=(is_null($user) || PEAR::isError($user))?'* unknown *':$user->getName();
  1487 + }
  1488 + else
  1489 + {
  1490 + $username = 'n/a';
  1491 + }
  1492 + $detail['owner'] = $username;
  1493 +
  1494 + $detail['is_immutable'] = (bool) $document->getImmutable();
  1495 +
  1496 +
1233 1497 $userid = $document->getCheckedOutUserID();
1234 1498  
1235 1499 if (is_numeric($userid))
... ... @@ -1241,7 +1505,20 @@ class KTAPI_Document extends KTAPI_FolderItem
1241 1505 {
1242 1506 $username = 'n/a';
1243 1507 }
1244   - $detail['checkout_by'] = $username;
  1508 + $detail['checked_out_by'] = $username;
  1509 +
  1510 + list($major, $minor, $fix) = explode('.', $default->systemVersion);
  1511 +
  1512 +
  1513 + if ($major == 3 && $minor >= 5)
  1514 + {
  1515 + $detail['checked_out_date'] = $document->getCheckedOutDate();
  1516 + }
  1517 + else
  1518 + {
  1519 + $detail['checked_out_date'] = $detail['modified_date'];
  1520 + }
  1521 + if (is_null($detail['checked_out_date'])) $detail['checked_out_date'] = 'n/a';
1245 1522  
1246 1523 $detail['full_path'] = $this->ktapi_folder->get_full_path() . '/' . $this->get_title();
1247 1524  
... ...
ktapi/KTAPIFolder.inc.php
... ... @@ -61,7 +61,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
61 61 * @param int $folderid
62 62 * @return KTAPI_Folder
63 63 */
64   - public static function &get(&$ktapi, $folderid)
  64 + function &get(&$ktapi, $folderid)
65 65 {
66 66 assert(!is_null($ktapi));
67 67 assert(is_a($ktapi, 'KTAPI'));
... ... @@ -93,7 +93,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
93 93 * @param Folder $folder
94 94 * @return KTAPI_Folder
95 95 */
96   - public function KTAPI_Folder(&$ktapi, &$folder)
  96 + function KTAPI_Folder(&$ktapi, &$folder)
97 97 {
98 98 $this->ktapi = &$ktapi;
99 99 $this->folder = &$folder;
... ... @@ -106,7 +106,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
106 106 * @access protected
107 107 * @return Folder
108 108 */
109   - public function &get_folder()
  109 + function &get_folder()
110 110 {
111 111 return $this->folder;
112 112 }
... ... @@ -117,7 +117,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
117 117 *
118 118 * @return array
119 119 */
120   - public function get_detail()
  120 + function get_detail()
121 121 {
122 122 $detail = array(
123 123 'id'=>(int) $this->folderid,
... ... @@ -129,12 +129,12 @@ class KTAPI_Folder extends KTAPI_FolderItem
129 129 return $detail;
130 130 }
131 131  
132   - public function get_parent_folder_id()
  132 + function get_parent_folder_id()
133 133 {
134 134 return (int) $this->folder->getParentID();
135 135 }
136 136  
137   - public function get_folder_name()
  137 + function get_folder_name()
138 138 {
139 139 return $this->folder->getFolderName($this->folderid);
140 140 }
... ... @@ -145,12 +145,12 @@ class KTAPI_Folder extends KTAPI_FolderItem
145 145 *
146 146 * @return int
147 147 */
148   - public function get_folderid()
  148 + function get_folderid()
149 149 {
150 150 return (int) $this->folderid;
151 151 }
152 152  
153   - public static function &_get_folder_by_name($ktapi, $foldername, $folderid)
  153 + function &_get_folder_by_name($ktapi, $foldername, $folderid)
154 154 {
155 155 $foldername=trim($foldername);
156 156 if (empty($foldername))
... ... @@ -189,12 +189,12 @@ class KTAPI_Folder extends KTAPI_FolderItem
189 189 * @param string $foldername
190 190 * @return KTAPI_Folder
191 191 */
192   - public function &get_folder_by_name($foldername)
  192 + function &get_folder_by_name($foldername)
193 193 {
194 194 return KTAPI_Folder::_get_folder_by_name($this->ktapi, $foldername, $this->folderid);
195 195 }
196 196  
197   - public function get_full_path()
  197 + function get_full_path()
198 198 {
199 199 $path = $this->folder->getFullPath() . '/' . $this->folder->getName();
200 200  
... ... @@ -209,7 +209,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
209 209 * @param string $function
210 210 * @return KTAPI_Document
211 211 */
212   - public function &_get_document_by_name($documentname, $function='getByNameAndFolder')
  212 + function &_get_document_by_name($documentname, $function='getByNameAndFolder')
213 213 {
214 214 $documentname=trim($documentname);
215 215 if (empty($documentname))
... ... @@ -272,7 +272,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
272 272 * @param string $documentname
273 273 * @return KTAPI_Document
274 274 */
275   - public function &get_document_by_name($documentname)
  275 + function &get_document_by_name($documentname)
276 276 {
277 277 return $this->_get_document_by_name($documentname,'getByNameAndFolder');
278 278 }
... ... @@ -284,12 +284,12 @@ class KTAPI_Folder extends KTAPI_FolderItem
284 284 * @param string $documentname
285 285 * @return KTAPI_Document
286 286 */
287   - public function &get_document_by_filename($documentname)
  287 + function &get_document_by_filename($documentname)
288 288 {
289 289 return $this->_get_document_by_name($documentname,'getByFilenameAndFolder');
290 290 }
291 291  
292   - public function _resolve_user($userid)
  292 + function _resolve_user($userid)
293 293 {
294 294 $user=null;
295 295  
... ... @@ -304,7 +304,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
304 304 return $user;
305 305 }
306 306  
307   - public function get_listing($depth=1, $what='DF')
  307 + function get_listing($depth=1, $what='DF')
308 308 {
309 309 if ($depth < 1)
310 310 {
... ... @@ -456,7 +456,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
456 456 * @param string $tempfilename This is a reference to the file that is accessible locally on the file system.
457 457 * @return KTAPI_Document
458 458 */
459   - public function &add_document($title, $filename, $documenttype, $tempfilename)
  459 + function &add_document($title, $filename, $documenttype, $tempfilename)
460 460 {
461 461 if (!is_file($tempfilename))
462 462 {
... ... @@ -514,7 +514,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
514 514 * @param string $foldername
515 515 * @return KTAPI_Folder
516 516 */
517   - public function &add_folder($foldername)
  517 + function &add_folder($foldername)
518 518 {
519 519 $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_ADD_FOLDER);
520 520  
... ... @@ -542,7 +542,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
542 542 *
543 543 * @param string $reason
544 544 */
545   - public function delete($reason)
  545 + function delete($reason)
546 546 {
547 547 $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_DELETE);
548 548 if (PEAR::isError($user))
... ... @@ -571,7 +571,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
571 571 *
572 572 * @param string $newname
573 573 */
574   - public function rename($newname)
  574 + function rename($newname)
575 575 {
576 576 $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_RENAME_FOLDER);
577 577 if (PEAR::isError($user))
... ... @@ -596,7 +596,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
596 596 * @param KTAPI_Folder $ktapi_target_folder
597 597 * @param string $reason
598 598 */
599   - public function move($ktapi_target_folder, $reason='')
  599 + function move($ktapi_target_folder, $reason='')
600 600 {
601 601 assert(!is_null($ktapi_target_folder));
602 602 assert(is_a($ktapi_target_folder,'KTAPI_Folder'));
... ... @@ -628,7 +628,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
628 628 * @param KTAPI_Folder $ktapi_target_folder
629 629 * @param string $reason
630 630 */
631   - public function copy($ktapi_target_folder, $reason='')
  631 + function copy($ktapi_target_folder, $reason='')
632 632 {
633 633 assert(!is_null($ktapi_target_folder));
634 634 assert(is_a($ktapi_target_folder,'KTAPI_Folder'));
... ... @@ -661,7 +661,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
661 661 * @access public
662 662 * @return array
663 663 */
664   - public function get_permissions()
  664 + function get_permissions()
665 665 {
666 666 return new PEAR_Error('TODO');
667 667 }
... ... @@ -672,7 +672,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
672 672 * @access public
673 673 * @return array
674 674 */
675   - public function get_transaction_history()
  675 + function get_transaction_history()
676 676 {
677 677 return new PEAR_Error('TODO');
678 678 }
... ...
ktapi/KTAPISession.inc.php
... ... @@ -36,7 +36,7 @@
36 36 *
37 37 */
38 38  
39   -abstract class KTAPI_Session
  39 +class KTAPI_Session
40 40 {
41 41 var $ktapi;
42 42 var $user = null;
... ... @@ -45,7 +45,7 @@ abstract class KTAPI_Session
45 45 var $active;
46 46 var $origUserId;
47 47  
48   - public function KTAPI_Session(&$ktapi, &$user)
  48 + function KTAPI_Session(&$ktapi, &$user)
49 49 {
50 50 assert(!is_null($ktapi));
51 51 assert(is_a($ktapi,'KTAPI'));
... ... @@ -64,7 +64,7 @@ abstract class KTAPI_Session
64 64 *
65 65 * @return string
66 66 */
67   - public function get_session()
  67 + function get_session()
68 68 {
69 69 return $this->session;
70 70 }
... ... @@ -74,7 +74,7 @@ abstract class KTAPI_Session
74 74 *
75 75 * @return int
76 76 */
77   - public function get_sessionid()
  77 + function get_sessionid()
78 78 {
79 79 return $this->sessionid;
80 80 }
... ... @@ -84,19 +84,19 @@ abstract class KTAPI_Session
84 84 *
85 85 * @return User
86 86 */
87   - public function &get_user()
  87 + function &get_user()
88 88 {
89 89 return $this->user;
90 90 }
91 91  
92   - public function logout()
  92 + function logout()
93 93 {
94 94 $_SESSION['userID'] = $this->origUserId;
95 95 $this->active=false;
96 96 // don't need to do anything really
97 97 }
98 98  
99   - public function is_active()
  99 + function is_active()
100 100 {
101 101 return $this->active;
102 102 }
... ... @@ -107,7 +107,7 @@ class KTAPI_UserSession extends KTAPI_Session
107 107 {
108 108 var $ip = null;
109 109  
110   - public function KTAPI_UserSession(&$ktapi, &$user, $session, $sessionid, $ip)
  110 + function KTAPI_UserSession(&$ktapi, &$user, $session, $sessionid, $ip)
111 111 {
112 112 parent::KTAPI_Session($ktapi, $user);
113 113  
... ... @@ -133,7 +133,7 @@ class KTAPI_UserSession extends KTAPI_Session
133 133 * @access private
134 134 * @return string
135 135 */
136   - public function resolveIP()
  136 + function resolveIP()
137 137 {
138 138 if (getenv("REMOTE_ADDR"))
139 139 {
... ... @@ -163,7 +163,7 @@ class KTAPI_UserSession extends KTAPI_Session
163 163 * @static
164 164 * @param User $user
165 165 */
166   - private function _check_session(&$user)
  166 + function _check_session(&$user)
167 167 {
168 168 $user_id = $user->getId();
169 169  
... ... @@ -218,7 +218,7 @@ class KTAPI_UserSession extends KTAPI_Session
218 218 * @param string $password
219 219 * @return KTAPI_Session
220 220 */
221   - public function &start_session(&$ktapi, $username, $password, $ip=null)
  221 + function &start_session(&$ktapi, $username, $password, $ip=null)
222 222 {
223 223 $this->active=false;
224 224 if ( empty($username) )
... ... @@ -272,7 +272,7 @@ class KTAPI_UserSession extends KTAPI_Session
272 272 * @param string $ip
273 273 * @return KTAPI_Session
274 274 */
275   - public function &get_active_session(&$ktapi, $session, $ip)
  275 + function &get_active_session(&$ktapi, $session, $ip)
276 276 {
277 277 $sql = "SELECT id, user_id FROM active_sessions WHERE session_id='$session'";
278 278 if (!empty($ip))
... ... @@ -313,7 +313,7 @@ class KTAPI_UserSession extends KTAPI_Session
313 313 * This closes the current session.
314 314 *
315 315 */
316   - public function logout()
  316 + function logout()
317 317 {
318 318 $sql = "DELETE FROM active_sessions WHERE id=$this->sessionid";
319 319 $result = DBUtil::runQuery($sql);
... ... @@ -332,7 +332,7 @@ class KTAPI_UserSession extends KTAPI_Session
332 332  
333 333 class KTAPI_AnonymousSession extends KTAPI_UserSession
334 334 {
335   - public function &start_session(&$ktapi, $ip=null)
  335 + function &start_session(&$ktapi, $ip=null)
336 336 {
337 337 $user =& User::get(-2);
338 338 if (is_null($user) || PEAR::isError($user) || ($user === false) || !$user->isAnonymous())
... ... @@ -370,7 +370,7 @@ class KTAPI_AnonymousSession extends KTAPI_UserSession
370 370  
371 371 class KTAPI_SystemSession extends KTAPI_Session
372 372 {
373   - public function KTAPI_SystemSession(&$ktapi, &$user)
  373 + function KTAPI_SystemSession(&$ktapi, &$user)
374 374 {
375 375 parent::KTAPI_Session($ktapi, $user);
376 376 $this->active=true;
... ...
ktwebdav/lib/KTWebDAVServer.inc.php
... ... @@ -1132,9 +1132,10 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1132 1132  
1133 1133 /**
1134 1134 * GET method helper
  1135 + * Method takes a directory path and checks whether it refers to a document or folder. The relevant folder and/or document id is returned.
1135 1136 *
1136   - * @param string directory path
1137   - * @return array or false
  1137 + * @param $path string The directory path
  1138 + * @return array or bool Either returns an array of folder/document id's or false if an error occurred
1138 1139 */
1139 1140 function _folderOrDocument($path) {
1140 1141  
... ... @@ -1142,14 +1143,14 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1142 1143  
1143 1144 $this->ktwebdavLog("Entering _folderOrDocument. path is " . $path, 'info', true);
1144 1145  
1145   - if ( !(strstr($path,"__BAOBABCLIENT__") === false) ) {
1146   - return array(0, 1);
1147   - }
1148   -
  1146 + /* ** Get the directory path and the folder/document being acted on ** */
1149 1147 $sFileName = basename($path);
1150 1148 // for windows replace backslash with forwardslash
1151 1149 $sFolderPath = str_replace("\\", '/', dirname($path) );
1152 1150  
  1151 + /* ** Get the starting point for recursing through the directory structure
  1152 + FolderId = 0 if we're in the root folder
  1153 + FolderId = 1 the starting point for locating any other folder ** */
1153 1154 if ($sFolderPath == "/" || $sFolderPath == "/ktwebdav") {
1154 1155 $this->ktwebdavLog("This is the root folder.", 'info', true);
1155 1156 $sFolderPath = $this->rootFolder;
... ... @@ -1164,6 +1165,9 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1164 1165 $this->ktwebdavLog("sFolderName is " . $sFolderPath, 'info', true);
1165 1166 $this->ktwebdavLog("iFolderID is " . $iFolderID, 'info', true);
1166 1167  
  1168 + /* ** Break up the directory path into its component directory's,
  1169 + recurse through the directory's to find the correct id of the current directory.
  1170 + Avoids situations where several directory's have the same name. ** */
1167 1171 $aFolderNames = split('/', $sFolderPath);
1168 1172  
1169 1173 $this->ktwebdavLog("aFolderNames are: " . print_r($aFolderNames, true), 'info', true);
... ... @@ -1196,6 +1200,9 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1196 1200 $this->ktwebdavLog("iFolderID set to " . $iFolderID, 'info', true);
1197 1201 }
1198 1202  
  1203 + /* ** Get the document id using the basename and parent folder id as parameters.
  1204 + If an id is obtained then the path refers to a document.
  1205 + If no id is returned then the path refers to a folder or a non-existing document. ** */
1199 1206 // FIXME: Direct database access
1200 1207 // $sQuery = "SELECT id FROM documents WHERE folder_id = ? AND filename = ? AND status_id = 1";
1201 1208 $sQuery = "SELECT D.id ";
... ... @@ -1214,12 +1221,18 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1214 1221 return false;
1215 1222 }
1216 1223  
  1224 + /* ** If the path refers to a folder or a non-existing document,
  1225 + Get the folder id using the basename and parent folder id as parameters.
  1226 + If an id is obtained then the path refers to an existing folder.
  1227 + If no id is returned and the basename is empty then path refers to the root folder.
  1228 + If no id is returned and the basename is not empty, then the path refers to either a non-existing folder or document. ** */
1217 1229 if ($iDocumentID === null) {
1218 1230 $this->ktwebdavLog("iDocumentID is null", 'info', true);
1219 1231 // FIXME: Direct database access
1220 1232 $sQuery = "SELECT id FROM folders WHERE parent_id = ? AND name = ?";
1221 1233 $aParams = array($iFolderID, $sFileName);
1222 1234 $id = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id');
  1235 +
1223 1236 if (PEAR::isError($id)) {
1224 1237 $this->ktwebdavLog("A DB(2) error occurred in _folderOrDocument", 'info', true);
1225 1238 return false;
... ... @@ -1235,6 +1248,7 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1235 1248 $this->ktwebdavLog("Setting Location Header to " . "Location: " . $_SERVER["PHP_SELF"] . "/", 'info', true);
1236 1249 header("Location: " . $_SERVER["PHP_SELF"] . "/");
1237 1250 }
  1251 + $this->ktwebdavLog("DEBUG: return id ".$id, 'info', true);
1238 1252 return array($id, null);
1239 1253 }
1240 1254  
... ... @@ -1647,24 +1661,16 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1647 1661  
1648 1662 /**
1649 1663 * MOVE method handler
  1664 + * Method checks if the source path refers to a document / folder then calls the appropriate method handler.
1650 1665 *
1651   - * @param array parameter passing array
  1666 + * @param $options array parameter passing array
1652 1667 * @return string HTTP status code or false
1653 1668 */
1654 1669 function MOVE($options)
1655 1670 {
1656   - // Use the WebDAV standards way.
1657   - // See rfc2518 Section 8.9
1658   - // This does a copy with delete
1659   - // FIXME: This way does not retain document history and other info
1660   -
1661   - //return $this->COPY($options, true);
1662   -
1663   - // Use the KT way.
1664   - // FIXME: This way does not allow overwrite
1665   -
1666 1671 $this->ktwebdavLog("Entering MOVE. options are " . print_r($options, true), 'info', true);
1667 1672  
  1673 + /* ** Check that write is allowed ** */
1668 1674 if ($this->checkSafeMode()) {
1669 1675  
1670 1676 if (!empty($_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
... ... @@ -1679,6 +1685,9 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1679 1685 }
1680 1686 */
1681 1687  
  1688 + /* ** Get the path to the document/folder to be copied.
  1689 + Call function to check if the path refers to a document or a folder.
  1690 + Return 404 error if the path is invalid. ** */
1682 1691 $source_path = $options["path"];
1683 1692  
1684 1693 // Fix for Mac Goliath
... ... @@ -1710,22 +1719,30 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1710 1719 return "404 Not found - Document was not found.";
1711 1720 }
1712 1721  
  1722 + /* ** Get the returned parent folder id and document/folder id.
  1723 + If the parent folder id is false, return 404 error.
  1724 + If the document id is either false or null, then the source is a folder.
  1725 + If the document id exists then the source is a document.
  1726 + If the source is a folder then call _MOVEFolder.
  1727 + If the source is a document then check if its checked out and call _MOVEDocument. ** */
1713 1728 list($iFolderID, $iDocumentID) = $source_res;
1714   - if ($iDocumentID === false) {
  1729 + if ($iFolderID === false && ($iDocumentID === false || is_null($iDocumentID))) {
1715 1730 $this->ktwebdavLog("404 Not found - Folder was not found.", 'info', true);
1716 1731 return "404 Not found - Folder was not found.";
1717 1732 }
1718 1733  
1719   - if (is_null($iDocumentID)) {
  1734 + if (is_null($iDocumentID) || $iDocumentID === false) {
1720 1735 // Source is a folder
  1736 + $this->ktwebdavLog("Source is a Folder.", 'info', true);
1721 1737 $movestat = $this->_MOVEFolder($options, $iFolderID);
1722 1738  
1723 1739 } else {
1724 1740 // Source is a document
  1741 + $this->ktwebdavLog("Source is a Document.", 'info', true);
1725 1742 if ($this->canCopyMoveRenameDocument($iDocumentID)) {
1726 1743 $movestat = $this->_MOVEDocument($options, $iFolderID, $iDocumentID);
1727 1744 } else {
1728   - return "Cannot MOVE document because it is checked out by another user.";
  1745 + return "423 Locked - Cannot MOVE document because it is checked out by another user.";
1729 1746 }
1730 1747 }
1731 1748  
... ... @@ -1746,7 +1763,9 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1746 1763 */
1747 1764 function _MOVEDocument($options, $iFolderID, $iDocumentID) {
1748 1765  
  1766 + /* ** Ensure that the destination path exists ** */
1749 1767 if ($options['dest'] == '') $options["dest"] = substr($options["dest_url"], strlen($_SERVER["SCRIPT_NAME"]));
  1768 + $this->ktwebdavLog("Entering _MOVEDocument. options are " . print_r($options, true), 'info', true);
1750 1769  
1751 1770 // Fix for Mac Goliath
1752 1771 // Modified - 25/10/07 - remove ktwebdav from document path
... ... @@ -1760,11 +1779,11 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1760 1779 }
1761 1780 }
1762 1781  
1763   - $this->ktwebdavLog("Entering _MOVEDocument. options are " . print_r($options, true), 'info', true);
1764 1782 global $default;
1765 1783 $new = true;
1766   - //FIXME: refactor me into KTDocumentUtil
1767 1784  
  1785 + /* ** Get the relevant paths. Get the basename of the destination path as the destination filename.
  1786 + Check whether the destination path refers to a folder / document. ** */
1768 1787 $oDocument = Document::get($iDocumentID);
1769 1788 $oSrcFolder = Folder::get($iFolderID);
1770 1789 $oUser =& User::get($this->userID);
... ... @@ -1772,36 +1791,16 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1772 1791 $source_path = $options["path"];
1773 1792 $dest_path = urldecode($options["dest"]);
1774 1793  
1775   - // Is this a rename?
1776   - if (dirname($source_path) == dirname($dest_path)) {
1777   - // This is a rename
1778   - //if ($options['overwrite'] != 'T') {
1779   - // $this->ktwebdavLog("This is a Rename. Overwrite needs to be TRUE.", 'info', true);
1780   - // return "412 Precondition Failed - This is a Rename. Overwrite needs to be TRUE.";
1781   - //}
1782   - $this->ktwebdavLog("Got an oDocument of " . print_r($oDocument, true), 'info', true);
1783   - $this->ktwebdavLog("Got a new name of " . basename($dest_path), 'info', true);
1784   -
1785   - // Check if the user has permissions to write this document
1786   - $oPerm =& KTPermission::getByName('ktcore.permissions.write');
1787   - $oUser =& User::get($this->userID);
1788   - if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDocument)) {
1789   - return "403 Forbidden - User does not have sufficient permissions";
1790   - }
1791   - $res = KTDocumentUtil::rename($oDocument, basename($dest_path), $oUser);
1792   - if (PEAR::isError($res) || is_null($res) || ($res === false)) {
1793   - return "404 Not Found - " . $res->getMessage();
1794   - } else {
1795   - $this->ktwebdavLog("201 Created", 'info', true);
1796   - return "201 Created";
1797   - }
1798   -
1799   - }
1800   -
  1794 + /* ** Get the source folder object.
  1795 + If the destination document is null, then the destination is a folder, continue.
  1796 + If the destination document returns an id, then the document exists. Check overwrite.
  1797 + If overwrite is true, then check permissions and delete the document, continue.
  1798 + If the destination document is false, then continue. ** */
1801 1799 list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
1802 1800  
1803 1801 if (is_null($iDestDoc)) {
1804 1802 // the dest is a folder
  1803 + $this->ktwebdavLog("Destination is a folder.", 'info', true);
1805 1804 } else if ($iDestDoc !== false) {
1806 1805 // Document exists
1807 1806 $this->ktwebdavLog("Destination Document exists.", 'info', true);
... ... @@ -1822,6 +1821,39 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1822 1821 $new = false;
1823 1822 }
1824 1823  
  1824 + /* ** Check if the source and destination directories are the same and the destination is not a folder.
  1825 + Then action is probably a rename.
  1826 + Check if user has permission to write to the document and folder.
  1827 + Rename the document. ** */
  1828 + if ((dirname($source_path) == dirname($dest_path)) && !is_null($iDestDoc)) {
  1829 + // This is a rename
  1830 + $this->ktwebdavLog("This is a rename.", 'info', true);
  1831 + $this->ktwebdavLog("Got an oDocument of " . print_r($oDocument, true), 'info', true);
  1832 + $this->ktwebdavLog("Got a new name of " . basename($dest_path), 'info', true);
  1833 +
  1834 + // Check if the user has permissions to write this document
  1835 + $oPerm =& KTPermission::getByName('ktcore.permissions.write');
  1836 + $oUser =& User::get($this->userID);
  1837 + if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDocument)) {
  1838 + return "403 Forbidden - User does not have sufficient permissions";
  1839 + }
  1840 +
  1841 + // Perform rename
  1842 + $res = KTDocumentUtil::rename($oDocument, basename($dest_path), $oUser);
  1843 + if (PEAR::isError($res) || is_null($res) || ($res === false)) {
  1844 + return "404 Not Found - " . $res->getMessage();
  1845 + } else if($new) {
  1846 + $this->ktwebdavLog("201 Created", 'info', true);
  1847 + return "201 Created";
  1848 + }else {
  1849 + $this->ktwebdavLog("204 No Content", 'info', true);
  1850 + return "204 No Content";
  1851 + }
  1852 + }
  1853 +
  1854 + /* ** Get the destination folder object and the source document object.
  1855 + Check if user has permission to write to the document and folder.
  1856 + Move the document. ** */
1825 1857 $oDestFolder = Folder::get($iDestFolder);
1826 1858 $this->ktwebdavLog("Got a destination folder of " . print_r($oDestFolder, true), 'info', true);
1827 1859  
... ... @@ -1832,57 +1864,20 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1832 1864 return "403 Forbidden - User does not have sufficient permissions";
1833 1865 }
1834 1866  
1835   - $oOriginalFolder = $oSrcFolder;
1836   - $iOriginalFolderPermissionObjectId = $oOriginalFolder->getPermissionObjectId();
1837   - $iDocumentPermissionObjectId = $oDocument->getPermissionObjectId();
  1867 + $reason = (isset($_SERVER['HTTP_REASON']) && !empty($_SERVER['HTTP_REASON'])) ? $_SERVER['HTTP_REASON'] : "KTWebDAV Move.";
1838 1868  
1839   - if ($iDocumentPermissionObjectId === $iOriginalFolderPermissionObjectId) {
1840   - $oDocument->setPermissionObjectId($oDestFolder->getPermissionObjectId());
1841   - }
  1869 + $res = KTDocumentUtil::move($oDocument, $oDestFolder, $oUser, $reason);
1842 1870  
1843   - //put the document in the new folder
1844   - $oDocument->setFolderID($oDestFolder->getId());
1845   - if (!$oDocument->update(true)) {
1846   - return "502 Bad Gateway - Document update failed.";
1847   - }
1848   -
1849   - //move the document on the file system
1850   - $oStorage =& KTStorageManagerUtil::getSingleton();
1851   - if (!$oStorage->moveDocument($oDocument, $oSrcFolder, $oDestFolder)) {
1852   - $oDocument->setFolderID($oSrcDocumentFolder->getId());
1853   - $oDocument->update(true);
1854   - return "502 Bad Gateway";
1855   - }
1856   -
1857   - $sMoveMessage = sprintf("Moved from %s/%s to %s/%s: %s",
1858   - $oSrcFolder->getFullPath(),
1859   - $oSrcFolder->getName(),
1860   - $oDestFolder->getFullPath(),
1861   - $oDestFolder->getName(),
1862   - $_SERVER['HTTP_REASON']);
1863   -
1864   - // create the document transaction record
1865   - $oDocumentTransaction = & new DocumentTransaction($oDocument, $sMoveMessage, 'ktcore.transactions.move');
1866   - $oDocumentTransaction->create();
1867   -
1868   - $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
1869   - $aTriggers = $oKTTriggerRegistry->getTriggers('moveDocument', 'postValidate');
1870   - foreach ($aTriggers as $aTrigger) {
1871   - $sTrigger = $aTrigger[0];
1872   - $oTrigger = new $sTrigger;
1873   - $aInfo = array(
1874   - "document" => $oDocument,
1875   - "old_folder" => $oSrcFolder,
1876   - "new_folder" => $oDestFolder,
1877   - );
1878   - $oTrigger->setInfo($aInfo);
1879   - $ret = $oTrigger->postValidate();
1880   - // FIXME: handle trigger subfailures.
  1871 + if(PEAR::isError($res)){
  1872 + $this->ktwebdavLog("Move on document failed: ".$res->getMessage(), 'info', true);
  1873 + return "500 Internal Server Error - Move on document failed.";
1881 1874 }
1882 1875  
1883 1876 if ($new) {
  1877 + $this->ktwebdavLog("201 Created", 'info', true);
1884 1878 return "201 Created";
1885 1879 } else {
  1880 + $this->ktwebdavLog("204 No Content", 'info', true);
1886 1881 return "204 No Content";
1887 1882 }
1888 1883 }
... ... @@ -1897,11 +1892,13 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1897 1892 */
1898 1893 function _MOVEFolder($options, $iFolderID) {
1899 1894  
  1895 + /* ** Ensure that the destination path exists ** */
1900 1896 if ($options['dest'] == '') $options["dest"] = substr($options["dest_url"], strlen($_SERVER["SCRIPT_NAME"]));
1901 1897 $this->ktwebdavLog("Entering _MOVEFolder. options are " . print_r($options, true), 'info', true);
1902 1898  
  1899 + /* ** RFC 2518 Section 8.9.2. A folder move must have a depth of 'infinity'.
  1900 + Check the requested depth. If depth is set to '0' or '1' return a 400 error. ** */
1903 1901 if ($options["depth"] != "infinity") {
1904   - // RFC 2518 Section 9.2, last paragraph
1905 1902 $this->ktwebdavLog("400 Bad request", 'info', true);
1906 1903 return "400 Bad request - depth must be 'inifinity'.";
1907 1904 }
... ... @@ -1920,23 +1917,75 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1920 1917  
1921 1918 global $default;
1922 1919  
  1920 + /* ** Get the relevant paths.
  1921 + Check whether the destination path refers to a folder / document. ** */
1923 1922 $source_path = $options["path"];
1924 1923 $dest_path = urldecode($options["dest"]);
  1924 + list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
1925 1925  
  1926 + /* ** Get the source folder objects.
  1927 + If the destination document is null, then the destination is an existing folder. Check overwrite.
  1928 + If overwrite is true, then check permissions and delete the folder, continue.
  1929 + If the destination document returns an id, then the destination is a document, check overwrite.
  1930 + If overwrite is true, then check permissions and delete the document, continue.
  1931 + If the destination document is false, then continue. ** */
1926 1932 $oSrcFolder = Folder::get($iFolderID);
  1933 + $oDestFolder = Folder::get($iDestFolder);
1927 1934  
1928   - list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
  1935 + $new = true;
  1936 + if (is_null($iDestDoc)) {
  1937 + // Folder exists
  1938 + $this->ktwebdavLog("Destination Folder exists.", 'info', true);
  1939 + $oReplaceFolder = $oDestFolder;
  1940 + if ($options['overwrite'] != 'T') {
  1941 + $this->ktwebdavLog("Overwrite needs to be TRUE.", 'info', true);
  1942 + return "412 Precondition Failed - Destination Folder exists. Overwrite needs to be TRUE.";
  1943 + }
  1944 + $this->ktwebdavLog("Overwrite is TRUE, deleting Destination Folder.", 'info', true);
1929 1945  
1930   - $oDestFolder = Folder::get($iDestFolder);
  1946 + // Check if the user has permissions to delete this folder
  1947 + $oPerm =& KTPermission::getByName('ktcore.permissions.delete');
  1948 + $oUser =& User::get($this->userID);
1931 1949  
1932   - // Is this a rename?
1933   - if (dirname($source_path) == dirname($dest_path)) {
1934   - // This is a rename
1935   - //if ($options['overwrite'] != 'T') {
1936   - // $this->ktwebdavLog("This is a Rename. Overwrite needs to be TRUE.", 'info', true);
1937   - // return "412 Precondition Failed - This is a Rename. Overwrite needs to be TRUE.";
1938   - //}
  1950 + if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oReplaceFolder)) {
  1951 + return "403 Forbidden - User does not have sufficient permissions";
  1952 + }
  1953 +
  1954 + KTFolderUtil::delete($oReplaceFolder, $oUser, 'KTWebDAV move overwrites target.');
  1955 +
  1956 + // Destination folder has been replaced so we need to get the parent folder object
  1957 + list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
  1958 + $oDestFolder = Folder::get($iDestFolder);
  1959 +
  1960 + $new = false;
  1961 + } else if ($iDestDoc !== false) {
  1962 + // Destination is a document
  1963 + $this->ktwebdavLog("Destination is a document.", 'info', true);
  1964 + $oReplaceDoc = Document::get($iDestDoc);
  1965 + if ($options['overwrite'] != 'T') {
  1966 + $this->ktwebdavLog("Overwrite needs to be TRUE.", 'info', true);
  1967 + return "412 Precondition Failed - Destination Folder is a document. Overwrite needs to be TRUE.";
  1968 + }
  1969 + $this->ktwebdavLog("Overwrite is TRUE, deleting Destination Document.", 'info', true);
  1970 +
  1971 + // Check if the user has permissions to delete this document
  1972 + $oPerm =& KTPermission::getByName('ktcore.permissions.delete');
  1973 + $oUser =& User::get($this->userID);
  1974 +
  1975 + if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oReplaceDoc)) {
  1976 + return "403 Forbidden - User does not have sufficient permissions";
  1977 + }
  1978 + KTDocumentUtil::delete($oReplaceDoc, 'KTWebDAV move overwrites target.');
  1979 + $new = false;
  1980 + }
1939 1981  
  1982 + /* ** Check if the source and destination directories are the same and the destination is not an existing folder.
  1983 + Then action is probably a rename.
  1984 + Check if user has permission to write to the folder.
  1985 + Rename the document. ** */
  1986 + if (dirname($source_path) == dirname($dest_path) && !is_null($iDestDoc)) {
  1987 + // This is a rename
  1988 + $this->ktwebdavLog("Rename collection.", 'info', true);
1940 1989 $this->ktwebdavLog("Got an oSrcFolder of " . print_r($oSrcFolder, true), 'info', true);
1941 1990 $this->ktwebdavLog("Got an new name of " . basename($dest_path), 'info', true);
1942 1991  
... ... @@ -1952,36 +2001,22 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1952 2001 if (PEAR::isError($res) || is_null($res) || ($res === false)) {
1953 2002 return "404 Not Found - " . $res->getMessage();
1954 2003 } else {
1955   - $this->ktwebdavLog("201 Created", 'info', true);
1956   - return "201 Created";
1957   - }
1958   -
1959   - }
1960   -
1961   - if (is_null($iDestDoc)) {
1962   - // the dest is a folder
1963   - } else if ($iDestDoc !== false) {
1964   - // Folder exists
1965   - $this->ktwebdavLog("Destination Folder exists.", 'info', true);
1966   - $oReplaceFolder = Folder::get($iDestDoc);
1967   - if ($options['overwrite'] != 'T') {
1968   - $this->ktwebdavLog("Overwrite needs to be TRUE.", 'info', true);
1969   - return "412 Precondition Failed - Destination Folder exists. Overwrite needs to be TRUE.";
  2004 + if($new){
  2005 + $this->ktwebdavLog("201 Created", 'info', true);
  2006 + return "201 Created";
  2007 + }else{
  2008 + $this->ktwebdavLog("204 No Content", 'info', true);
  2009 + return "204 No Content";
  2010 + }
1970 2011 }
1971   - $this->ktwebdavLog("Overwrite is TRUE, deleting Destination Folder.", 'info', true);
1972 2012  
1973   - // Check if the user has permissions to delete this folder
1974   - $oPerm =& KTPermission::getByName('ktcore.permissions.delete');
1975   - $oUser =& User::get($this->userID);
1976   - if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oReplaceFolder)) {
1977   - return "403 Forbidden - User does not have sufficient permissions";
1978   - }
1979   - KTFolderUtil::delete($oReplaceFolder, 'KTWebDAV move overwrites target.');
1980   - $new = false;
1981 2013 }
1982 2014  
1983 2015 include_once(KT_LIB_DIR . '/foldermanagement/folderutil.inc.php');
1984 2016  
  2017 + /* ** Get the destination folder object and the source document object.
  2018 + Check if user has permission to write to the folder.
  2019 + Move the folder. ** */
1985 2020 $oUser =& User::get($this->userID);
1986 2021 $this->ktwebdavLog("Got an oSrcFolder of " . print_r($oSrcFolder, true), 'info', true);
1987 2022 $this->ktwebdavLog("Got an oDestFolder of " . print_r($oDestFolder, true), 'info', true);
... ... @@ -1993,18 +2028,29 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1993 2028 if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDestFolder)) {
1994 2029 return "403 Forbidden - User does not have sufficient permissions";
1995 2030 }
1996   - KTFolderUtil::move($oSrcFolder, $oDestFolder, $oUser);
1997 2031  
1998   - $this->ktwebdavLog("201 Created", 'info', true);
1999   - return "201 Created";
  2032 + $res = KTFolderUtil::move($oSrcFolder, $oDestFolder, $oUser);
  2033 +
  2034 + if(PEAR::isError($res)){
  2035 + $this->ktwebdavLog("Move on folder failed: ".$res->getMessage(), 'info', true);
  2036 + return "500 Internal Server Error - Move on folder failed.";
  2037 + }
2000 2038  
  2039 + if($new){
  2040 + $this->ktwebdavLog("201 Created", 'info', true);
  2041 + return "201 Created";
  2042 + }else{
  2043 + $this->ktwebdavLog("204 No Content", 'info', true);
  2044 + return "204 No Content";
  2045 + }
2001 2046 }
2002 2047  
2003 2048 /**
2004 2049 * COPY method handler
  2050 + * Method checks if the source path refers to a document / folder then calls the appropriate method handler.
2005 2051 *
2006   - * @param array parameter passing array
2007   - * @param string delete source flag
  2052 + * @param $options array parameter passing array
  2053 + * @param $del string delete source flag
2008 2054 * @return string HTTP status code or false
2009 2055 */
2010 2056 function COPY($options, $del = false)
... ... @@ -2012,6 +2058,7 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
2012 2058 $this->ktwebdavLog("Entering COPY. options are " . print_r($options, true), 'info', true);
2013 2059 $this->ktwebdavLog("del is: " . $del, 'info', true);
2014 2060  
  2061 + /* ** Check that writing to the server is allowed * **/
2015 2062 if ($this->checkSafeMode()) {
2016 2063  
2017 2064 if (!empty($_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
... ... @@ -2025,6 +2072,10 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
2025 2072 return "502 bad gateway - No copying to different WebDAV Servers yet";
2026 2073 }
2027 2074 */
  2075 +
  2076 + /* ** Get the path to the document/folder to be copied.
  2077 + Call function to check if the path refers to a document or a folder.
  2078 + Return 404 error if the path is invalid. ** */
2028 2079 $source_path = $options["path"];
2029 2080 $this->ktwebdavLog("SourcePath is: " . $source_path, 'info', true);
2030 2081 $source_res = $this->_folderOrDocument($source_path);
... ... @@ -2033,13 +2084,19 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
2033 2084 return "404 Not found - The document could not be found.";
2034 2085 }
2035 2086  
  2087 + /* ** Get the returned parent folder id and document/folder id.
  2088 + If the parent folder id is false, return 404 error.
  2089 + If the document id is either false or null, then the source is a folder.
  2090 + If the document id exists then the source is a document.
  2091 + If the source is a folder then call _COPYFolder.
  2092 + If the source is a document then check if its checked out and call _COPYDocument. ** */
2036 2093 list($iFolderID, $iDocumentID) = $source_res;
2037   - if ($iDocumentID === false) {
  2094 + if ($iFolderID === false && ($iDocumentID === false || is_null($iDocumentID))) {
2038 2095 $this->ktwebdavLog("404 Not found - The folder could not be found.", 'info', true);
2039 2096 return "404 Not found - The folder could not be found.";
2040 2097 }
2041 2098  
2042   - if (is_null($iDocumentID)) {
  2099 + if (is_null($iDocumentID) || $iDocumentID === false) {
2043 2100 // Source is a folder
2044 2101 $this->ktwebdavLog("Source is a Folder.", 'info', true);
2045 2102 $copystat = $this->_COPYFolder($options, $iFolderID);
... ... @@ -2049,13 +2106,15 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
2049 2106 $this->ktwebdavLog("Source is a Document.", 'info', true);
2050 2107  
2051 2108 if ($this->canCopyMoveRenameDocument($iDocumentID)) {
2052   - $copystat = $this->_COPYDocument($options, $iFolderID, $iDocumentID, $dest_folder_id);
  2109 + $copystat = $this->_COPYDocument($options, $iFolderID, $iDocumentID);
2053 2110 } else {
2054   - return "Cannot COPY document because it is checked out by another user.";
  2111 + // Document is locked
  2112 + return "423 Locked - Cannot COPY document because it is checked out by another user.";
2055 2113 }
2056 2114  
2057 2115 }
2058 2116  
  2117 + /* ** Deprecated. If the request is a move then delete the source **
2059 2118 // Delete the source if this is a move and the copy was ok
2060 2119 if ($del && ($copystat{0} == "2")) {
2061 2120 $delstat = $this->DELETE(array("path" => $options["path"]));
... ... @@ -2064,6 +2123,7 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
2064 2123 return $delstat;
2065 2124 }
2066 2125 }
  2126 + */
2067 2127  
2068 2128 $this->ktwebdavLog("Final copystat result is: " . $copystat, 'info', true);
2069 2129 return $copystat;
... ... @@ -2074,16 +2134,30 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
2074 2134 /**
2075 2135 * COPY method helper for Documents
2076 2136 *
2077   - * @param array parameter passing array
2078   - * @param int Folder ID
2079   - * @param int Document ID
  2137 + * @param $options array parameter passing array
  2138 + * @param $iFolderID int Folder ID
  2139 + * @param $iDocumentID int Document ID
2080 2140 * @return string HTTP status code or false
2081 2141 */
2082 2142 function _COPYDocument($options, $iFolderID, $iDocumentID) {
2083 2143  
  2144 + /* ** Ensure that the destination path exists ** */
2084 2145 if ($options['dest'] == '') $options["dest"] = substr($options["dest_url"], strlen($_SERVER["SCRIPT_NAME"]));
2085 2146 $this->ktwebdavLog("Entering _COPYDocument. options are " . print_r($options, true), 'info', true);
2086 2147  
  2148 + /* ** Get the relevant paths. Get the basename of the destination path as the destination filename.
  2149 + Check whether the destination path refers to a folder / document. ** */
  2150 + $source_path = $options["path"];
  2151 + $dest_path = urldecode($options["dest"]);
  2152 + $sDestFileName = basename($dest_path);
  2153 +
  2154 + list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
  2155 +
  2156 + if($iDestFolder === false){
  2157 + return "409 Conflict - Destination folder does not exist.";
  2158 + }
  2159 +
  2160 + /* ** Depth must be infinity to copy a document ** */
2087 2161 if ($options["depth"] != "infinity") {
2088 2162 // RFC 2518 Section 9.2, last paragraph
2089 2163 $this->ktwebdavLog("400 Bad request", 'info', true);
... ... @@ -2092,17 +2166,20 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
2092 2166  
2093 2167 global $default;
2094 2168  
2095   - $source_path = $options["path"];
2096   - $dest_path = urldecode($options["dest"]);
2097   -
  2169 + /* ** Get the source folder object.
  2170 + If the destination document is null, then the destination is a folder, set the destination filename to empty, continue.
  2171 + If the destination document returns an id, then the document exists. Check overwrite.
  2172 + If overwrite is true, then check permissions and delete the document, continue.
  2173 + If the destination document is false, then continue. ** */
2098 2174 $oSrcFolder = Folder::get($iFolderID);
2099 2175  
2100   - list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
2101   -
  2176 + $new = true;
2102 2177 if (is_null($iDestDoc)) {
2103 2178 // the dest is a folder
2104 2179 // $this->ktwebdavLog("400 Bad request", 'info', true);
2105   - return "400 Bad request - Destination is a Folder";
  2180 + $this->ktwebdavLog("Destination is a folder.", 'info', true);
  2181 + $sDestFileName = '';
  2182 + //return "400 Bad request - Destination is a Folder";
2106 2183 } else if ($iDestDoc !== false) {
2107 2184 // Document exists
2108 2185 $this->ktwebdavLog("Destination Document exists.", 'info', true);
... ... @@ -2123,25 +2200,33 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
2123 2200 $new = false;
2124 2201 }
2125 2202  
  2203 + /* ** Get the destination folder object and the source document object.
  2204 + Check if user has permission to write to the document and folder.
  2205 + Copy the document. ** */
2126 2206 $oDestFolder = Folder::get($iDestFolder);
2127 2207 $oSrcDoc = Document::get($iDocumentID);
2128 2208  
2129 2209 include_once(KT_LIB_DIR . '/foldermanagement/folderutil.inc.php');
2130 2210  
2131   - $this->ktwebdavLog("Got an oSrcDoc of " . print_r($oSrcDoc, true), 'info', true);
2132   - $this->ktwebdavLog("Got an oDestFolder of " . print_r($oDestFolder, true), 'info', true);
  2211 + $this->ktwebdavLog("Got an oSrcDoc of " .$oSrcDoc->getName() . print_r($oSrcDoc, true), 'info', true);
  2212 + $this->ktwebdavLog("Got an oDestFolder of " .$oDestFolder->getName() . print_r($oDestFolder, true), 'info', true);
2133 2213  
2134 2214 // Check if the user has permissions to write in this folder
2135 2215 $oPerm =& KTPermission::getByName('ktcore.permissions.write');
2136 2216 $oUser =& User::get($this->userID);
2137   - if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oSrcDoc)) {
  2217 + if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDestFolder)) {
2138 2218 return "403 Forbidden - User does not have sufficient permissions";
2139 2219 }
2140   - KTDocumentUtil::copy($oSrcDoc, $oDestFolder, $_SERVER['HTTP_REASON']);
2141 2220  
2142   - // FIXME: Do failure checking here
  2221 + $reason = (isset($_SERVER['HTTP_REASON']) && !empty($_SERVER['HTTP_REASON'])) ? $_SERVER['HTTP_REASON'] : "KTWebDAV Copy.";
  2222 +
  2223 + $oDesDoc = KTDocumentUtil::copy($oSrcDoc, $oDestFolder, $reason, $sDestFileName);
  2224 +
  2225 + if(PEAR::isError($oDesDoc)){
  2226 + $this->ktwebdavLog("Copy on document failed: ".$oDesDoc->getMessage(), 'info', true);
  2227 + return "500 Internal Server Error - Copy on document failed.";
  2228 + }
2143 2229  
2144   - $new = false;
2145 2230 if ($new) {
2146 2231 $this->ktwebdavLog("201 Created", 'info', true);
2147 2232 return "201 Created";
... ... @@ -2160,37 +2245,52 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
2160 2245 */
2161 2246 function _COPYFolder($options, $iFolderID) {
2162 2247  
  2248 + /* ** Ensure that the destination path exists ** */
2163 2249 if ($options['dest'] == '') $options["dest"] = substr($options["dest_url"], strlen($_SERVER["SCRIPT_NAME"]));
2164 2250 $this->ktwebdavLog("Entering _COPYFolder. options are " . print_r($options, true), 'info', true);
2165 2251  
  2252 + /* ** RFC 2518 Section 8.8.3. DAV compliant servers must support depth headers of '0' and 'infinity'.
  2253 + Check the requested depth. If depth is set to '0', set copyall to false. A depth of 0 indicates
  2254 + that the folder is copied without any children. If depth is set to '1', return a 400 error. ** */
  2255 + $copyAll = true;
2166 2256 if ($options["depth"] != "infinity") {
2167   - // RFC 2518 Section 9.2, last paragraph
2168   - $this->ktwebdavLog("400 Bad request", 'info', true);
2169   - return "400 Bad request - Depth must be 'infinity'.";
  2257 + if($options['depth'] == '0'){
  2258 + $copyAll = false;
  2259 + $this->ktwebdavLog("Depth is 0. Copy only the base folder.", 'info', true);
  2260 + }else{
  2261 + $this->ktwebdavLog("400 Bad request. Depth must be infinity or 0.", 'info', true);
  2262 + return "400 Bad request - Depth must be 'infinity' or '0'.";
  2263 + }
2170 2264 }
2171 2265  
2172 2266 global $default;
2173 2267  
2174 2268 $new = true;
2175 2269  
  2270 + /* ** Get the relevant paths. Get the basename of the destination path as the destination path name.
  2271 + Check whether the destination path refers to a folder / document. ** */
2176 2272 $source_path = $options["path"];
2177 2273 $dest_path = urldecode($options["dest"]);
2178   -
2179   - $oSrcFolder = Folder::get($iFolderID);
  2274 + $sDestPathName = basename($dest_path);
2180 2275  
2181 2276 list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
2182 2277  
  2278 + /* ** Get the source and destination folder objects.
  2279 + If the destination document is null, then the destination is an existing folder. Check overwrite.
  2280 + If overwrite is true, then check permissions and delete the folder, continue.
  2281 + If the destination document returns an id, then the destination is a document, return 409 error.
  2282 + If the destination document is false, then continue. ** */
  2283 + $oSrcFolder = Folder::get($iFolderID);
2183 2284 $oDestFolder = Folder::get($iDestFolder);
2184 2285  
2185 2286 include_once(KT_LIB_DIR . '/foldermanagement/folderutil.inc.php');
2186 2287  
2187   - if (is_null($iDestDoc)) {
2188   - // the dest is a folder
2189   - $this->ktwebdavLog("The Destination is a Folder.", 'info', true);
2190   - } else if ($iDestDoc !== false) {
2191   - // Folder exists
  2288 + if(is_null($iDestDoc)) {
  2289 + // Destination is a folder and exists
  2290 + //$sDestPathName = '';
2192 2291 $this->ktwebdavLog("Destination Folder exists.", 'info', true);
2193   - $oReplaceFolder = Folder::get($iDestDoc);
  2292 +
  2293 + $oReplaceFolder = $oDestFolder;
2194 2294 if ($options['overwrite'] != 'T') {
2195 2295 $this->ktwebdavLog("Overwrite needs to be TRUE.", 'info', true);
2196 2296 return "412 Precondition Failed - Destination Folder exists. Overwrite needs to be TRUE.";
... ... @@ -2203,10 +2303,21 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
2203 2303 if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oReplaceFolder)) {
2204 2304 return "403 Forbidden - User does not have sufficient permissions";
2205 2305 }
2206   - KTFolderUtil::delete($oReplaceFolder, 'KTWebDAV move overwrites target.');
  2306 + KTFolderUtil::delete($oReplaceFolder, $oUser, 'KTWebDAV move overwrites target.');
  2307 +
  2308 + // Destination folder has been deleted - get new object of destination parent folder
  2309 + list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
  2310 + $oDestFolder = Folder::get($iDestFolder);
  2311 +
2207 2312 $new = false;
  2313 + } else if ($iDestDoc !== false) {
  2314 + // Destination is a document
  2315 + return "409 Conflict - Can't write a collection to a document";
2208 2316 }
2209 2317  
  2318 + /* ** Get the destination folder object and the source document object.
  2319 + Check if user has permission to write to the folder.
  2320 + Copy the document. Pass parameters for the destination folder name and the depth of copy. ** */
2210 2321 $oUser =& User::get($this->userID);
2211 2322 $this->ktwebdavLog("Got an oSrcFolder of " . print_r($oSrcFolder, true), 'info', true);
2212 2323 $this->ktwebdavLog("Got an oDestFolder of " . print_r($oDestFolder, true), 'info', true);
... ... @@ -2218,7 +2329,15 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
2218 2329 if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDestFolder)) {
2219 2330 return "403 Forbidden - User does not have sufficient permissions";
2220 2331 }
2221   - KTFolderUtil::copy($oSrcFolder, $oDestFolder, $oUser, 'KTWebDAV Copy.');
  2332 +
  2333 + $reason = (isset($_SERVER['HTTP_REASON']) && !empty($_SERVER['HTTP_REASON'])) ? $_SERVER['HTTP_REASON'] : "KTWebDAV Copy.";
  2334 +
  2335 + $res = KTFolderUtil::copy($oSrcFolder, $oDestFolder, $oUser, $reason, $sDestPathName, $copyAll);
  2336 +
  2337 + if(PEAR::isError($res)){
  2338 + $this->ktwebdavLog("Copy on folder failed: ".$res->getMessage(), 'info', true);
  2339 + return "500 Internal Server Error - Copy on folder failed.";
  2340 + }
2222 2341  
2223 2342 if ($new) {
2224 2343 $this->ktwebdavLog("201 Created", 'info', true);
... ...
ktwebservice/nunit/authentication.cs
... ... @@ -14,7 +14,7 @@ namespace MonoTests.KnowledgeTree
14 14 [SetUp]
15 15 public void SetUp()
16 16 {
17   - this._kt = new KnowledgeTreeService();
  17 + this._kt = new KTWebService();
18 18 }
19 19  
20 20 [TearDown]
... ...
ktwebservice/nunit/document_add.cs
... ... @@ -5,55 +5,34 @@ using System.IO;
5 5 namespace MonoTests.KnowledgeTree
6 6 {
7 7 [TestFixture]
8   - public class AddDocumentTest
  8 + public class AddDocumentTest : KTTest
9 9 {
10 10  
11   - private String _session;
12   - private KnowledgeTreeService _kt;
  11 +
13 12 private int _docId;
14 13 private int _folderId;
15 14 private String _filename;
16   - private String _content;
17   - private bool _verbose;
18   -
19   - public AddDocumentTest()
20   - {
21   -
22   - this._verbose = true;
  15 + private String _content;
23 16  
  17 + public AddDocumentTest() : base()
  18 + {
24 19 this._folderId = 1;
25   - }
26   -
  20 + }
27 21  
28 22 [SetUp]
29 23 public void SetUp()
30   - {
31   - this._kt = new KnowledgeTreeService();
32   - //this._kt.Url = "http://ktdms.trunk/ktwebservice/webservice.php";
33   - kt_response response = this._kt.login("admin","admin","127.0.0.1");
34   - this._session = response.message;
35   -
  24 + {
36 25 this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt";
37 26 this._content = "hello world!";
38 27  
39   - Helper.writeFile(this._filename, this._content);
40   -
41   -
42   - }
  28 + Helper.writeFile(this._filename, this._content); }
43 29  
44 30 [TearDown]
45 31 public void TearDown()
46   - {
47   -
48   - Helper.deleteFile(this._filename);
49   -
50   -
51   - this._kt.logout(this._session);
52   - }
53   -
54   -
55   -
56   -
  32 + {
  33 + Helper.deleteFile(this._filename);
  34 + }
  35 +
57 36 [Test]
58 37 public void FindDocumentBeforeAdd()
59 38 {
... ... @@ -70,8 +49,7 @@ namespace MonoTests.KnowledgeTree
70 49 {
71 50 System.Console.WriteLine("document not found. that is ok!");
72 51 }
73   - }
74   -
  52 + }
75 53  
76 54 [Test]
77 55 public void FindFolderBeforeAdd()
... ... @@ -89,8 +67,7 @@ namespace MonoTests.KnowledgeTree
89 67 {
90 68 if (this._verbose) System.Console.WriteLine("folder not found. that is ok!");
91 69 }
92   - }
93   -
  70 + }
94 71  
95 72 [Test]
96 73 public void AddDocument()
... ... @@ -121,9 +98,9 @@ namespace MonoTests.KnowledgeTree
121 98 Assert.AreEqual("Administrator", response1.created_by);
122 99  
123 100 //Assert.IsTrue(response1.updated_date == null);
124   - Assert.IsTrue("" != response1.updated_date);
  101 + Assert.IsTrue("" != response1.modified_date);
125 102  
126   - Assert.AreEqual("Administrator", response1.updated_by);
  103 + Assert.AreEqual("Administrator", response1.modified_by);
127 104  
128 105 Assert.IsTrue(response1.document_id > 0);
129 106  
... ... @@ -185,7 +162,7 @@ namespace MonoTests.KnowledgeTree
185 162 String filename = "kt unit test31";
186 163  
187 164 if (this._verbose) System.Console.WriteLine("Adding document : " + filename);
188   - FileUploader uploader = new FileUploader("http://ktdms.trunk/ktwebservice/upload.php");
  165 + FileUploader uploader = new FileUploader();
189 166  
190 167 uploader.upload(this._session, this._filename);
191 168 String tempname = uploader.getFilename();
... ... @@ -203,10 +180,10 @@ namespace MonoTests.KnowledgeTree
203 180  
204 181 Assert.AreEqual("Administrator", response1.created_by);
205 182  
206   - //Assert.IsTrue(response1.updated_date == null);
207   - Assert.IsTrue("" != response1.updated_date);
  183 + //Assert.IsTrue(response1.modified_date == null);
  184 + Assert.IsTrue("" != response1.modified_date);
208 185  
209   - Assert.AreEqual("Administrator", response1.updated_by);
  186 + Assert.AreEqual("Administrator", response1.modified_by);
210 187  
211 188 Assert.IsTrue(response1.document_id > 0);
212 189  
... ...
ktwebservice/nunit/document_checkout.cs
... ... @@ -5,24 +5,18 @@ using System.IO;
5 5 namespace MonoTests.KnowledgeTree
6 6 {
7 7 [TestFixture]
8   - public class CheckoutDocumentTest
9   - {
10   - private String _session;
11   - private KnowledgeTreeService _kt;
  8 + public class CheckoutDocumentTest : KTTest
  9 + {
12 10 private int _docId;
13 11 private int _folderId;
14 12 private String _filename;
15   - private String _content;
16   - private bool _verbose;
  13 + private String _content;
17 14  
18 15  
19 16 [SetUp]
20 17 public void SetUp()
21 18 {
22   - this._kt = new KnowledgeTreeService();
23   - kt_response response = this._kt.login("admin","admin","127.0.0.1");
24   - this._session = response.message;
25   -
  19 +
26 20 this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt";
27 21  
28 22 String filename = "kt unit test1";
... ... @@ -31,7 +25,7 @@ namespace MonoTests.KnowledgeTree
31 25  
32 26 Helper.writeFile(this._filename, this._content);
33 27  
34   - this._verbose = false;
  28 +
35 29  
36 30 this._folderId = 1;
37 31  
... ... @@ -56,9 +50,7 @@ namespace MonoTests.KnowledgeTree
56 50 if (this._verbose && response.status_code != 0)
57 51 {
58 52 System.Console.WriteLine("Could not delete file: " + this._filename);
59   - }
60   -
61   - this._kt.logout(this._session);
  53 + }
62 54  
63 55 }
64 56  
... ... @@ -69,12 +61,15 @@ namespace MonoTests.KnowledgeTree
69 61  
70 62 if (this._verbose) System.Console.WriteLine("Checking out document : " + filename);
71 63  
72   - kt_response response = this._kt.checkout_base64_document(this._session, this._docId, "unit test - going to checkout and then undo", false);
  64 + kt_document_detail response = this._kt.checkout_base64_document(this._session, this._docId, "unit test - going to checkout and then undo", false);
73 65 Assert.AreEqual(0, response.status_code);
74   -
  66 + Assert.AreEqual("Administrator",response.checked_out_by);
  67 + Assert.IsTrue(null != response.checked_out_date);
75 68  
76 69 response = this._kt.undo_document_checkout(this._session, this._docId, "unit test - doing undo");
77 70 Assert.AreEqual(0, response.status_code);
  71 + Assert.AreEqual("n/a",response.checked_out_by);
  72 + Assert.AreEqual("n/a", response.checked_out_date);
78 73 }
79 74  
80 75 [Test]
... ... @@ -84,14 +79,16 @@ namespace MonoTests.KnowledgeTree
84 79  
85 80 if (this._verbose) System.Console.WriteLine("Checking out document : " + filename);
86 81  
87   - kt_response response = this._kt.checkout_base64_document(this._session, this._docId, "unit test - going to checkout and then checkin", false);
  82 + kt_document_detail response = this._kt.checkout_base64_document(this._session, this._docId, "unit test - going to checkout and then checkin", false);
88 83 Assert.AreEqual(0, response.status_code);
  84 + Assert.AreEqual("Administrator",response.checked_out_by);
  85 + Assert.IsTrue(null != response.checked_out_date);
89 86  
90 87  
91 88 kt_document_detail checkin = this._kt.checkin_base64_document(this._session, this._docId, filename, "unit test - doing checkin", Helper.ConvertFileToBase64Encoding(this._filename), false);
92 89 Assert.AreEqual(0, checkin.status_code);
93   -
94   - //assert - check data checkout
  90 + Assert.AreEqual("n/a",checkin.checked_out_by);
  91 + Assert.AreEqual("n/a", checkin.checked_out_date);
95 92 }
96 93  
97 94 [Test]
... ... @@ -101,17 +98,20 @@ namespace MonoTests.KnowledgeTree
101 98  
102 99 if (this._verbose) System.Console.WriteLine("Checking out document : " + filename);
103 100  
104   - kt_response response = this._kt.checkout_document(this._session, this._docId, "unit test - going to checkout and then checkin", false);
  101 + kt_document_detail response = this._kt.checkout_document(this._session, this._docId, "unit test - going to checkout and then checkin", false);
105 102 Assert.AreEqual(0, response.status_code);
  103 + Assert.AreEqual("Administrator",response.checked_out_by);
  104 + Assert.IsTrue(null != response.checked_out_date);
106 105  
107   -
108   - FileUploader uploader = new FileUploader("http://ktdms.trunk/ktwebservice/upload.php");
  106 + FileUploader uploader = new FileUploader();
109 107  
110 108 uploader.upload(this._session, this._filename);
111 109 String tempname = uploader.getFilename();
112 110  
113 111 kt_document_detail checkin = this._kt.checkin_document(this._session, this._docId, filename, "unit test - doing checkin", tempname, false);
114   - Assert.AreEqual(0, checkin.status_code);
  112 + Assert.AreEqual(0, checkin.status_code);
  113 + Assert.AreEqual("n/a",checkin.checked_out_by);
  114 + Assert.AreEqual("n/a", checkin.checked_out_date);
115 115 }
116 116  
117 117  
... ...
ktwebservice/nunit/document_copy.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 +
  8 +
  9 + [TestFixture]
  10 + public class DocumentCopyTest : KTTest
  11 + {
  12 + private int _folderId;
  13 + private Document _doc1;
  14 +
  15 +
  16 + [SetUp]
  17 + public void SetUp()
  18 + {
  19 + this._folderId = 1;
  20 +
  21 + this._doc1 = new Document(1, this._session, this._kt, this._verbose, false);
  22 + this._doc1.createFile(this._folderId);
  23 +
  24 +
  25 +
  26 + }
  27 +
  28 + [TearDown]
  29 + public void TearDown()
  30 + {
  31 + this._doc1.deleteFile();
  32 + }
  33 +
  34 + [Test]
  35 + public void FindDocumentBeforeCopy()
  36 + {
  37 + String filename = "Root Folder/test123";
  38 + if (this._verbose) System.Console.WriteLine("Finding document before add: " + filename);
  39 + kt_document_detail documentDetail = this._kt.get_document_detail_by_title(this._session, 1, filename, "");
  40 + if (0 == documentDetail.status_code)
  41 + {
  42 + if (this._verbose) System.Console.WriteLine("Found document - deleting");
  43 + kt_response response = this._kt.delete_document(this._session, documentDetail.document_id, "Delete - cleaning up before add");
  44 + Assert.AreEqual(0, response.status_code);
  45 + }
  46 + else if (this._verbose)
  47 + {
  48 + System.Console.WriteLine("document not found. that is ok!");
  49 + }
  50 + }
  51 +
  52 +
  53 + [Test]
  54 + public void CopyTest()
  55 + {
  56 + kt_document_detail linkresp = this._kt.copy_document(this._session, this._doc1.docId, 1, "copy", "test123", "test123.txt");
  57 + Assert.AreEqual(0, linkresp.status_code);
  58 + Assert.AreEqual("test123.txt", linkresp.filename);
  59 + Assert.AreEqual("test123", linkresp.title);
  60 +
  61 +
  62 +
  63 + }
  64 +
  65 + [Test]
  66 + public void FindDocumentAfterCopy()
  67 + {
  68 + String filename = "Root Folder/test123";
  69 + if (this._verbose) System.Console.WriteLine("Finding document before add: " + filename);
  70 + kt_document_detail documentDetail = this._kt.get_document_detail_by_title(this._session, 1, filename, "");
  71 + Assert.AreEqual(0, documentDetail.status_code);
  72 +
  73 + if (this._verbose) System.Console.WriteLine("Found document - deleting");
  74 + kt_response response = this._kt.delete_document(this._session, documentDetail.document_id, "Delete - cleaning up before add");
  75 + Assert.AreEqual(0, response.status_code);
  76 +
  77 + }
  78 +
  79 +
  80 +
  81 + }
  82 +}
... ...
ktwebservice/nunit/document_detail.cs
... ... @@ -5,23 +5,17 @@ using System.IO;
5 5 namespace MonoTests.KnowledgeTree
6 6 {
7 7 [TestFixture]
8   - public class DocumentDetailTest
9   - {
10   - private String _session;
11   - private KnowledgeTreeService _kt;
  8 + public class DocumentDetailTest : KTTest
  9 + {
12 10 private int _docId;
13 11 private int _folderId;
14 12 private String _filename;
15   - private String _content;
16   - private bool _verbose;
  13 + private String _content;
17 14  
18 15  
19 16 [SetUp]
20 17 public void SetUp()
21   - {
22   - this._kt = new KnowledgeTreeService();
23   - kt_response response = this._kt.login("admin","admin","127.0.0.1");
24   - this._session = response.message;
  18 + {
25 19  
26 20 this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt";
27 21  
... ... @@ -29,10 +23,7 @@ namespace MonoTests.KnowledgeTree
29 23  
30 24 this._content = "hello world!";
31 25  
32   - Helper.writeFile(this._filename, this._content);
33   -
34   - this._verbose = false;
35   -
  26 + Helper.writeFile(this._filename, this._content);
36 27 this._folderId = 1;
37 28  
38 29 kt_document_detail response1 = this._kt.add_base64_document(this._session, this._folderId, filename, this._filename, "Default", Helper.ConvertFileToBase64Encoding(this._filename));
... ... @@ -56,9 +47,7 @@ namespace MonoTests.KnowledgeTree
56 47 if (this._verbose && response.status_code != 0)
57 48 {
58 49 System.Console.WriteLine("Could not delete file: " + this._filename);
59   - }
60   -
61   - this._kt.logout(this._session);
  50 + }
62 51  
63 52 }
64 53  
... ...
ktwebservice/nunit/document_download.cs
... ... @@ -8,40 +8,25 @@ namespace MonoTests.KnowledgeTree
8 8  
9 9  
10 10 [TestFixture]
11   - public class DocumentSystemMetadataTest
  11 + public class DocumentSystemMetadataTest : KTTest
12 12 {
13   - private String _session;
14   - private KnowledgeTreeService _kt;
15 13 private int _folderId;
16   - private bool _verbose;
17 14 private Document _doc1;
18 15  
19 16  
20 17 [SetUp]
21 18 public void SetUp()
22 19 {
23   - this._kt = new KnowledgeTreeService();
24   - kt_response response = this._kt.login("admin","admin","127.0.0.1");
25   - this._session = response.message;
26   -
27 20 this._folderId = 1;
28 21  
29   -
30 22 this._doc1 = new Document(1, this._session, this._kt, this._verbose,false);
31 23 this._doc1.createFile(this._folderId);
32   -
33   -
34   - this._verbose = true;
35   -
36 24 }
37 25  
38 26 [TearDown]
39 27 public void TearDown()
40 28 {
41 29 this._doc1.deleteFile();
42   -
43   - this._kt.logout(this._session);
44   -
45 30 }
46 31  
47 32 [Test]
... ...
ktwebservice/nunit/document_history.cs
... ... @@ -5,36 +5,24 @@ using System.IO;
5 5 namespace MonoTests.KnowledgeTree
6 6 {
7 7 [TestFixture]
8   - public class DocumentHistoryTest
  8 + public class DocumentHistoryTest : KTTest
9 9 {
10   - private String _session;
11   - private KnowledgeTreeService _kt;
12 10 private int _folderId;
13   - private bool _verbose;
14 11 private Document _doc1;
15 12  
16 13 [SetUp]
17 14 public void SetUp()
18 15 {
19   - this._kt = new KnowledgeTreeService();
20   - kt_response response = this._kt.login("admin","admin","127.0.0.1");
21   - this._session = response.message;
22   -
23 16 this._folderId = 1;
24 17  
25 18 this._doc1 = new Document(1, this._session, this._kt, this._verbose,false);
26 19 this._doc1.createFile(this._folderId);
27   -
28   - this._verbose = true;
29   -
30 20 }
31 21  
32 22 [TearDown]
33 23 public void TearDown()
34 24 {
35 25 this._doc1.deleteFile();
36   -
37   - this._kt.logout(this._session);
38 26 }
39 27  
40 28 [Test]
... ...
ktwebservice/nunit/document_links.cs
... ... @@ -7,12 +7,9 @@ namespace MonoTests.KnowledgeTree
7 7  
8 8  
9 9 [TestFixture]
10   - public class DocumentLinkTest
  10 + public class DocumentLinkTest : KTTest
11 11 {
12   - private String _session;
13   - private KnowledgeTreeService _kt;
14 12 private int _folderId;
15   - private bool _verbose;
16 13 private Document _doc1;
17 14 private Document _doc2;
18 15  
... ... @@ -20,21 +17,12 @@ namespace MonoTests.KnowledgeTree
20 17 [SetUp]
21 18 public void SetUp()
22 19 {
23   - this._kt = new KnowledgeTreeService();
24   - kt_response response = this._kt.login("admin","admin","127.0.0.1");
25   - this._session = response.message;
26   -
27 20 this._folderId = 1;
28 21  
29   -
30 22 this._doc1 = new Document(1, this._session, this._kt, this._verbose, false);
31 23 this._doc1.createFile(this._folderId);
32 24 this._doc2 = new Document(2, this._session, this._kt, this._verbose, false);
33 25 this._doc2.createFile(this._folderId);
34   -
35   -
36   - this._verbose = true;
37   -
38 26 }
39 27  
40 28 [TearDown]
... ... @@ -42,9 +30,6 @@ namespace MonoTests.KnowledgeTree
42 30 {
43 31 this._doc1.deleteFile();
44 32 this._doc2.deleteFile();
45   -
46   - this._kt.logout(this._session);
47   -
48 33 }
49 34  
50 35 [Test]
... ...
ktwebservice/nunit/document_metadata.cs
... ... @@ -5,25 +5,17 @@ using System.IO;
5 5 namespace MonoTests.KnowledgeTree
6 6 {
7 7 [TestFixture]
8   - public class DocumentMetadataTest
  8 + public class DocumentMetadataTest : KTTest
9 9 {
10   - private String _session;
11   - private KnowledgeTreeService _kt;
12 10 private int _docId;
13 11 private int _folderId;
14 12 private String _filename;
15 13 private String _content;
16   - private bool _verbose;
17 14  
18 15  
19 16 [SetUp]
20 17 public void SetUp()
21 18 {
22   - this._kt = new KnowledgeTreeService();
23   -
24   - kt_response response = this._kt.login("admin","admin","127.0.0.1");
25   - this._session = response.message;
26   -
27 19 this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt";
28 20  
29 21 String filename = "kt unit test1";
... ... @@ -32,8 +24,6 @@ namespace MonoTests.KnowledgeTree
32 24  
33 25 Helper.writeFile(this._filename, this._content);
34 26  
35   - this._verbose = false;
36   -
37 27 this._folderId = 1;
38 28  
39 29 kt_document_detail response1 = this._kt.add_base64_document(this._session, this._folderId, filename, this._filename, "Default", Helper.ConvertFileToBase64Encoding(this._filename));
... ... @@ -58,9 +48,6 @@ namespace MonoTests.KnowledgeTree
58 48 {
59 49 System.Console.WriteLine("Could not delete file: " + this._filename);
60 50 }
61   -
62   - this._kt.logout(this._session);
63   -
64 51 }
65 52  
66 53 [Test]
... ...
ktwebservice/nunit/document_owner.cs
... ... @@ -5,38 +5,24 @@ using System.IO;
5 5 namespace MonoTests.KnowledgeTree
6 6 {
7 7 [TestFixture]
8   - public class DocumentOwnerTest
  8 + public class DocumentOwnerTest : KTTest
9 9 {
10   - private String _session;
11   - private KnowledgeTreeService _kt;
12 10 private int _folderId;
13   - private bool _verbose;
14 11 private Document _doc1;
15 12  
16 13 [SetUp]
17 14 public void SetUp()
18 15 {
19   - this._kt = new KnowledgeTreeService();
20   - kt_response response = this._kt.login("admin","admin","127.0.0.1");
21   - this._session = response.message;
22   -
23 16 this._folderId = 1;
24 17  
25   -
26 18 this._doc1 = new Document(1, this._session, this._kt, this._verbose, false);
27 19 this._doc1.createFile(this._folderId);
28   -
29   - this._verbose = true;
30   -
31 20 }
32 21  
33 22 [TearDown]
34 23 public void TearDown()
35 24 {
36 25 this._doc1.deleteFile();
37   -
38   - this._kt.logout(this._session);
39   -
40 26 }
41 27  
42 28 [Test]
... ...
ktwebservice/nunit/document_rename.cs
... ... @@ -5,36 +5,24 @@ using System.IO;
5 5 namespace MonoTests.KnowledgeTree
6 6 {
7 7 [TestFixture]
8   - public class DocumentRenameTest
  8 + public class DocumentRenameTest : KTTest
9 9 {
10   - private String _session;
11   - private KnowledgeTreeService _kt;
12 10 private int _folderId;
13   - private bool _verbose;
14 11 private Document _doc1;
15 12  
16 13 [SetUp]
17 14 public void SetUp()
18 15 {
19   - this._kt = new KnowledgeTreeService();
20   - kt_response response = this._kt.login("admin","admin","127.0.0.1");
21   - this._session = response.message;
22   -
23 16 this._folderId = 1;
24 17  
25 18 this._doc1 = new Document(1, this._session, this._kt, this._verbose,false);
26 19 this._doc1.createFile(this._folderId);
27   -
28   - this._verbose = true;
29   -
30 20 }
31 21  
32 22 [TearDown]
33 23 public void TearDown()
34 24 {
35 25 this._doc1.deleteFile();
36   -
37   - this._kt.logout(this._session);
38 26 }
39 27  
40 28 [Test]
... ...
ktwebservice/nunit/document_system_metadata.cs
... ... @@ -7,12 +7,9 @@ namespace MonoTests.KnowledgeTree
7 7  
8 8  
9 9 [TestFixture]
10   - public class DocumentSystemMetadataTest
  10 + public class DocumentSystemMetadataTest : KTTest
11 11 {
12   - private String _session;
13   - private KnowledgeTreeService _kt;
14 12 private int _folderId;
15   - private bool _verbose;
16 13 private Document _doc1;
17 14 private Document _doc2;
18 15  
... ... @@ -20,20 +17,12 @@ namespace MonoTests.KnowledgeTree
20 17 [SetUp]
21 18 public void SetUp()
22 19 {
23   - this._kt = new KnowledgeTreeService();
24   - kt_response response = this._kt.login("admin","admin","127.0.0.1");
25   - this._session = response.message;
26   -
27 20 this._folderId = 1;
28 21  
29 22  
30 23 this._doc1 = new Document(1, this._session, this._kt, this._verbose,false);
31 24 this._doc1.createFile(this._folderId);
32 25 this._doc2 = new Document(2, this._session, this._kt, this._verbose,true);
33   -
34   -
35   - this._verbose = true;
36   -
37 26 }
38 27  
39 28 [TearDown]
... ... @@ -41,12 +30,9 @@ namespace MonoTests.KnowledgeTree
41 30 {
42 31 this._doc1.deleteFile();
43 32 this._doc2.deleteFile();
44   -
45   - this._kt.logout(this._session);
46   -
47 33 }
48 34  
49   - [Test]
  35 +// [Test]
50 36 public void UpdateDocumentMetadataTest()
51 37 {
52 38  
... ... @@ -64,13 +50,16 @@ namespace MonoTests.KnowledgeTree
64 50 fs[0].fields[2].name = "Media Type";
65 51 fs[0].fields[2].value = "Text";
66 52  
67   - kt_sysdata_item[] sysdata = new kt_sysdata_item[2];
  53 + kt_sysdata_item[] sysdata = new kt_sysdata_item[3];
68 54 sysdata[0] = new kt_sysdata_item();
69 55 sysdata[0].name = "created_by";
70 56 sysdata[0].value = "Anonymous";
71 57 sysdata[1] = new kt_sysdata_item();
72 58 sysdata[1].name = "created_date";
73 59 sysdata[1].value = "2007-01-17";
  60 + sysdata[2] = new kt_sysdata_item();
  61 + sysdata[2].name = "modified_by";
  62 + sysdata[2].value = "admin";
74 63  
75 64  
76 65 kt_document_detail update_resp = this._kt.update_document_metadata(this._session, this._doc1.docId, fs, sysdata);
... ... @@ -88,9 +77,11 @@ namespace MonoTests.KnowledgeTree
88 77  
89 78 Assert.AreEqual("Anonymous", update_resp.created_by);
90 79 Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date);
  80 + Assert.AreEqual("Administrator", update_resp.modified_by);
  81 + Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date);
91 82 }
92 83  
93   - [Test]
  84 +// [Test]
94 85 public void AddSmallDocumentWithMetadataTest()
95 86 {
96 87 kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1];
... ... @@ -134,7 +125,7 @@ namespace MonoTests.KnowledgeTree
134 125 Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date);
135 126 }
136 127  
137   - [Test]
  128 +// [Test]
138 129 public void CheckinSmallDocumentWithMetadataTest()
139 130 {
140 131 kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1];
... ... @@ -159,7 +150,7 @@ namespace MonoTests.KnowledgeTree
159 150 sysdata[1].name = "created_date";
160 151 sysdata[1].value = "2007-01-17";
161 152  
162   - kt_response resp = this._kt.checkout_base64_document(this._session, this._doc1.docId, "test checkin", false);
  153 + kt_document_detail resp = this._kt.checkout_base64_document(this._session, this._doc1.docId, "test checkin", false);
163 154 Assert.AreEqual(0, resp.status_code);
164 155  
165 156  
... ... @@ -181,7 +172,83 @@ namespace MonoTests.KnowledgeTree
181 172 Assert.AreEqual("Anonymous", update_resp.created_by);
182 173 Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date);
183 174 }
  175 +
  176 + [Test]
  177 + public void AddDocumentWithMetadataTest()
  178 + {
  179 + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1];
  180 + fs[0] = new kt_metadata_fieldset();
  181 + fs[0].fieldset = "General information";
  182 + fs[0].fields = new kt_metadata_field[3];
  183 + fs[0].fields[0] = new kt_metadata_field();
  184 + fs[0].fields[0].name = "Document Author";
  185 + fs[0].fields[0].value = "Joe Soap";
  186 + fs[0].fields[1] = new kt_metadata_field();
  187 + fs[0].fields[1].name = "Category";
  188 + fs[0].fields[1].value = "Technical";
  189 + fs[0].fields[2] = new kt_metadata_field();
  190 + fs[0].fields[2].name = "Media Type";
  191 + fs[0].fields[2].value = "Text";
  192 +
  193 + kt_sysdata_item[] sysdata = new kt_sysdata_item[2];
  194 + sysdata[0] = new kt_sysdata_item();
  195 + sysdata[0].name = "created_by";
  196 + sysdata[0].value = "Anonymous";
  197 + sysdata[1] = new kt_sysdata_item();
  198 + sysdata[1].name = "created_date";
  199 + sysdata[1].value = "2007-01-17";
  200 +
  201 +
  202 +
  203 + this._doc2.local = true;
  204 + this._doc2.createFile(this._folderId);
  205 +
  206 +
  207 + FileUploader uploader = new FileUploader( );
  208 +
  209 + uploader.upload(this._session, this._doc2.filename);
  210 +
  211 + System.Console.WriteLine("uploaded: " + uploader.filename);
  212 + kt_document_detail response1 = this._kt.add_document_with_metadata(this._session, this._folderId, this._doc2.title, this._doc2.filename, "Default", uploader.filename,fs, sysdata);
  213 +
  214 + Assert.AreEqual(0, response1.status_code);
  215 + }
184 216  
  217 + [Test]
  218 + public void CheckinDocumentWithMetadataTest()
  219 + {
  220 + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1];
  221 + fs[0] = new kt_metadata_fieldset();
  222 + fs[0].fieldset = "General information";
  223 + fs[0].fields = new kt_metadata_field[3];
  224 + fs[0].fields[0] = new kt_metadata_field();
  225 + fs[0].fields[0].name = "Document Author";
  226 + fs[0].fields[0].value = "Joe Soap";
  227 + fs[0].fields[1] = new kt_metadata_field();
  228 + fs[0].fields[1].name = "Category";
  229 + fs[0].fields[1].value = "Technical";
  230 + fs[0].fields[2] = new kt_metadata_field();
  231 + fs[0].fields[2].name = "Media Type";
  232 + fs[0].fields[2].value = "Text";
  233 +
  234 + kt_sysdata_item[] sysdata = new kt_sysdata_item[2];
  235 + sysdata[0] = new kt_sysdata_item();
  236 + sysdata[0].name = "created_by";
  237 + sysdata[0].value = "Anonymous";
  238 + sysdata[1] = new kt_sysdata_item();
  239 + sysdata[1].name = "created_date";
  240 + sysdata[1].value = "2007-01-17";
  241 +
  242 + kt_document_detail resp = this._kt.checkout_base64_document(this._session, this._doc1.docId, "test checkin", false);
  243 + Assert.AreEqual(0, resp.status_code);
  244 +
  245 + FileUploader uploader = new FileUploader( );
  246 +
  247 + uploader.upload(this._session, this._doc1.filename);
  248 +
  249 + kt_document_detail update_resp = this._kt.checkin_document(this._session, this._doc1.docId, this._doc1.filename, "unit test - doing checkin", uploader.filename, false);
  250 + Assert.AreEqual(0, update_resp.status_code);
  251 + }
185 252  
186 253 }
187 254 }
... ...
ktwebservice/nunit/document_type.cs
... ... @@ -5,21 +5,14 @@ using System.IO;
5 5 namespace MonoTests.KnowledgeTree
6 6 {
7 7 [TestFixture]
8   - public class DocumentOwnerTest
  8 + public class DocumentOwnerTest : KTTest
9 9 {
10   - private String _session;
11   - private KnowledgeTreeService _kt;
12   - private int _folderId;
13   - private bool _verbose;
  10 + private int _folderId;
14 11 private Document _doc1;
15 12  
16 13 [SetUp]
17 14 public void SetUp()
18 15 {
19   - this._kt = new KnowledgeTreeService();
20   - kt_response response = this._kt.login("admin","admin","127.0.0.1");
21   - this._session = response.message;
22   -
23 16 this._folderId = 1;
24 17  
25 18  
... ... @@ -34,9 +27,6 @@ namespace MonoTests.KnowledgeTree
34 27 public void TearDown()
35 28 {
36 29 this._doc1.deleteFile();
37   -
38   - this._kt.logout(this._session);
39   -
40 30 }
41 31  
42 32 [Test]
... ...
ktwebservice/nunit/document_workflow.cs
... ... @@ -5,35 +5,24 @@ using System.IO;
5 5 namespace MonoTests.KnowledgeTree
6 6 {
7 7 [TestFixture]
8   - public class WorkflowTest
9   - {
10   - private String _session;
11   - private KnowledgeTreeService _kt;
12   - private int _folderId;
13   - private bool _verbose;
  8 + public class WorkflowTest : KTTest
  9 + {
  10 + private int _folderId;
14 11 private Document _doc1;
15 12  
16 13 [SetUp]
17 14 public void SetUp()
18   - {
19   - this._kt = new KnowledgeTreeService();
20   - kt_response response = this._kt.login("admin","admin","127.0.0.1");
21   - this._session = response.message;
22   -
23   - this._folderId = 1;
24   -
25   -
  15 + {
  16 + this._folderId = 1;
  17 +
26 18 this._doc1 = new Document(1, this._session, this._kt, this._verbose, false);
27   - this._doc1.createFile(this._folderId);
28   -
29   - this._verbose = true;
  19 + this._doc1.createFile(this._folderId);
30 20 }
31 21  
32 22 [TearDown]
33 23 public void TearDown()
34 24 {
35   - this._doc1.deleteFile();
36   - this._kt.logout(this._session);
  25 + this._doc1.deleteFile();
37 26 }
38 27  
39 28 [Test]
... ...
ktwebservice/nunit/folder.cs
... ... @@ -5,28 +5,20 @@ using System.IO;
5 5 namespace MonoTests.KnowledgeTree
6 6 {
7 7 [TestFixture]
8   - public class FolderTest
  8 + public class FolderTest : KTTest
9 9 {
10   -
11   - private String _session;
12   - private KnowledgeTreeService _kt;
  10 +
13 11 private int _folder_id;
14 12 private int _subfolder_id;
15 13  
16 14 [SetUp]
17 15 public void SetUp()
18 16 {
19   - this._kt = new KnowledgeTreeService();
20   - kt_response response = this._kt.login("admin","admin","127.0.0.1");
21   - this._session = response.message;
22   -
23 17 }
24 18  
25 19 [TearDown]
26 20 public void TearDown()
27   - {
28   -
29   - this._kt.logout(this._session);
  21 + {
30 22 }
31 23  
32 24 [Test]
... ...
ktwebservice/nunit/helper.cs
1 1 using System;
2 2 using System.Text;
3 3 using System.Net;
4   -using System.IO;
  4 +using System.IO;
  5 +using System.Collections;
5 6  
6 7 namespace MonoTests.KnowledgeTree
7 8 {
  9 +
  10 +
  11 +
  12 + [System.Web.Services.WebServiceBinding(Name="KnowledgeTreePort", Namespace="urn:KnowledgeTree")]
  13 + public class KTWebService : KnowledgeTreeService
  14 + {
  15 + public KTWebService() : base()
  16 + {
  17 + this.Url = Environment.GetEnvironmentVariable("KT_ROOT_URL") + "/ktwebservice/webservice.php";
  18 + }
  19 + }
  20 +
  21 + public class KTTest
  22 + {
  23 + protected KTWebService _kt;
  24 + protected String _session;
  25 + protected bool _verbose;
  26 +
  27 + public KTTest()
  28 + {
  29 + this._kt = new KTWebService();
  30 + kt_response response = this._kt.login("admin","admin","127.0.0.1");
  31 + this._session = response.message;
  32 + this._verbose = false;
  33 +
  34 + }
  35 +
  36 + ~KTTest()
  37 + {
  38 + this._kt.logout(this._session);
  39 + }
  40 + }
  41 +
  42 +
  43 +
8 44 public class FileUploader
9 45 {
10 46 private String boundary;
11 47 private String uri;
12   - private String filename;
  48 + public String filename;
13 49  
14 50  
15 51 public FileUploader(String uri)
16 52 {
17 53 this.uri = uri;
  54 + System.Console.WriteLine("Using upload URL: " + uri);
18 55 this.boundary = "----" + DateTime.Now.Ticks.ToString("x");
19 56 }
  57 +
  58 + public FileUploader() : this(Environment.GetEnvironmentVariable("KT_ROOT_URL") + "/ktwebservice/upload.php")
  59 + {
  60 + }
  61 +
20 62  
21 63 public String getFilename()
22 64 {
... ... @@ -125,6 +167,8 @@ namespace MonoTests.KnowledgeTree
125 167 }
126 168  
127 169 }
  170 +
  171 +
128 172  
129 173 public class Document
130 174 {
... ...
ktwebservice/nunit/makefile
1   -RESULTS=authentication.result document_detail.result document_links.result document_owner.result document_type.result document_history.result document_rename.result document_workflow.result document_metadata.result folder.result document_add.result document_system_metadata.result document_checkout.result
  1 +RESULTS= authentication.result document_detail.result document_add.result document_checkout.result document_type.result document_links.result document_owner.result document_rename.result document_history.result document_workflow.result document_copy.result folder.result document_metadata.result document_system_metadata.result
2 2 #document_download.result
3 3 PROXY=KTproxy.cs
4 4 WSDL=ktdms.wsdl
5   -WSDL_URL=http://ktdms.trunk/ktwebservice/index.php?wsdl
  5 +ROOT_URL=http://ktdms.trunk
  6 +WSDL_URL=${ROOT_URL}/ktwebservice/index.php?wsdl
6 7  
7 8 all: ${RESULTS}
8 9  
... ... @@ -11,6 +12,8 @@ results: clean-results ${RESULTS}
11 12 KTproxy.dll: KTproxy.cs helper.cs
12 13 mcs -r:System.Web.Services /target:library KTproxy.cs helper.cs
13 14  
  15 +
  16 +
14 17 KTproxy.cs: ktdms.wsdl
15 18 wsdl -out:${PROXY} ${WSDL}
16 19  
... ... @@ -23,9 +26,9 @@ clean:
23 26 clean-results:
24 27 rm -f ${RESULTS}
25 28  
26   -%.dll: %.cs KTproxy.dll
27   - mcs -r:System.Web.Services -r:nunit.framework /r:KTproxy.dll -debug /target:library -out:$@ $<
  29 +%.dll: %.cs KTproxy.dll
  30 + mcs -r:System.Web.Services -r:nunit.framework /r:KTproxy.dll -debug /target:library -out:$@ $<
28 31  
29 32 %.result: %.dll
30   - nunit-console $<
  33 + (export KT_ROOT_URL=${ROOT_URL}; nunit-console $<)
31 34 mv TestResult.xml $@
... ...
ktwebservice/nunit/query.cs
... ... @@ -5,25 +5,18 @@ using System.IO;
5 5 namespace MonoTests.KnowledgeTree
6 6 {
7 7 [TestFixture]
8   - public class QueryTest
  8 + public class QueryTest : KTTest
9 9 {
10   -
11   - private String _session;
12   - private KnowledgeTreeService _kt;
  10 +
13 11  
14 12 [SetUp]
15 13 public void SetUp()
16   - {
17   - this._kt = new KnowledgeTreeService();
18   - kt_response response = this._kt.login("admin","admin","127.0.0.1");
19   - this._session = response.message;
20   -
  14 + {
21 15 }
22 16  
23 17 [TearDown]
24 18 public void TearDown()
25   - {
26   - this._kt.logout(this._session);
  19 + {
27 20 }
28 21  
29 22 [Test]
... ...
ktwebservice/proxy/proxy.php deleted
1   -<?php
2   -
3   -/**
4   - * $Id:$
5   - *
6   - * KnowledgeTree Open Source Edition
7   - * Document Management Made Simple
8   - * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
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 The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
23   - * Blake Street, Observatory, 7925 South Africa. 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   -
39   -set_time_limit(0);
40   -
41   -if ($argc < 3)
42   -{
43   - die('Usage: proxy.php listenport connectaddr connectport');
44   -}
45   -
46   -$cport = $argv[1];
47   -$saddress = $argv[2];
48   -$sport = $argv[2];
49   -
50   -
51   -print "Listening on port: $cport\n";
52   -print "Connecting to: $saddress:$sport\n";
53   -
54   -if (($lsock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false)
55   -{
56   - die('Cannot create socket: '. socket_strerror($res));
57   -}
58   -
59   -if (($res = @socket_bind($lsock, '127.0.0.2', $cport)) === false)
60   -{
61   - die('Cannot bind socket: ' . socket_strerror($res));
62   -}
63   -
64   -if (($res = socket_listen($lsock, 5)) === false)
65   -{
66   - die('Cannot listen on socket: ' . socket_strerror($res));
67   -}
68   -
69   -while(true)
70   -{
71   - if (($csock = socket_accept($lsock)) < 0)
72   - {
73   - print 'Cannot accept socket: ' . socket_strerror($csock) . "\n";
74   - continue;
75   - }
76   - print "accepting client\n";
77   -
78   - if (($ssock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0)
79   - {
80   - print('Cannot create socket: '. socket_strerror($res));
81   - continue;
82   - }
83   -
84   - print "connecting\n";
85   - if (($res = socket_connect($ssock, $saddress, $sport)) < 0)
86   - {
87   - print('Cannot bind socket: ' . socket_strerror($res));
88   - continue;
89   - }
90   -
91   -
92   - ob_implicit_flush();
93   -
94   - $clientClose = false;
95   - $serverClose = false;
96   - while(!$clientClose && !$serverClose)
97   - {
98   - $arr = array();
99   - $carr = array();
100   - $sarr = array();
101   -
102   - if (!$clientClose)
103   - {
104   - $arr[]= $csock;
105   - $carr[]= $csock;
106   - }
107   - if (!$serverClose)
108   - {
109   - $arr[]= $ssock;
110   - $sarr[]= $ssock;
111   - }
112   -ob_implicit_flush(); $res = socket_select($arr, $e2=null, $e = null, 5);
113   - if ($res === false)
114   - {
115   - print "problem\n";
116   - break;
117   - }
118   - else
119   - {
120   - $res = @socket_select($carr, $w = NULL, $e = NULL, 0);
121   - if (!$clientClose && ($res === 1))
122   - {
123   - $buf = @socket_read($csock, 2048, PHP_NORMAL_READ);
124   - if (strlen($buf) != 0)
125   - {
126   - socket_write($ssock, $buf, strlen($buf));
127   - print "C>>S: $buf\n";
128   - }
129   - if ($buf === false)
130   - {
131   - $clientClose = true;
132   - socket_write($ssock, "\n", 1);
133   - print "close connection to client\n";
134   - }
135   -
136   - }
137   - $res = @socket_select($sarr, $w = NULL, $e = NULL, 0);
138   - if (!$serverClose && ($res === 1))
139   - {
140   - $buf = @socket_read($ssock, 2048, PHP_NORMAL_READ);
141   - if (strlen($buf) != 0)
142   - {
143   - socket_write($csock, $buf, strlen($buf));
144   - print "C<<S: $buf\n";
145   -
146   - }
147   - if($buf ===0 )
148   - {
149   - print "\n";
150   - }
151   - if ($buf === false)
152   - {
153   - //socket_close($csock);
154   - $serverClose = true;
155   - print "close connection to server\n";
156   - }
157   - }
158   - }
159   - }
160   - socket_close($ssock);
161   - socket_close($csock);
162   -}
163   -
164   -socket_close($lsock);
165   -?>
166 0 \ No newline at end of file
ktwebservice/webservice.php
1 1 <?php
2   -
  2 +//debugger_start_debug();
3 3 /**
4 4 *
5 5 * $Id$
... ... @@ -9,36 +9,35 @@
9 9 * KnowledgeTree Open Source Edition
10 10 * Document Management Made Simple
11 11 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
12   - *
  12 + *
13 13 * This program is free software; you can redistribute it and/or modify it under
14 14 * the terms of the GNU General Public License version 3 as published by the
15 15 * Free Software Foundation.
16   - *
  16 + *
17 17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 20 * details.
21   - *
  21 + *
22 22 * You should have received a copy of the GNU General Public License
23 23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24   - *
  24 + *
25 25 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
26 26 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
27   - *
  27 + *
28 28 * The interactive user interfaces in modified source and object code versions
29 29 * of this program must display Appropriate Legal Notices, as required under
30 30 * Section 5 of the GNU General Public License version 3.
31   - *
  31 + *
32 32 * In accordance with Section 7(b) of the GNU General Public License version 3,
33 33 * these Appropriate Legal Notices must retain the display of the "Powered by
34   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  34 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
35 35 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
36   - * must display the words "Powered by KnowledgeTree" and retain the original
37   - * copyright notice.
  36 + * must display the words "Powered by KnowledgeTree" and retain the original
  37 + * copyright notice.
38 38 * Contributor( s): ______________________________________
39 39 *
40 40 */
41   -
42 41 require_once('../config/dmsDefaults.php');
43 42 require_once('../ktapi/ktapi.inc.php');
44 43 require_once('SOAP/Server.php');
... ... @@ -46,7 +45,19 @@ require_once(&#39;SOAP/Disco.php&#39;);
46 45 require_once('KTDownloadManager.inc.php');
47 46 require_once('KTUploadManager.inc.php');
48 47 require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php');
49   -require_once(KT_DIR . '/search2/search/search.inc.php');
  48 +
  49 +list($major, $minor, $fix) = explode('.', $default->systemVersion);
  50 +
  51 +if ($major == 3 && $minor >= 5)
  52 +{
  53 + define('HAS_SEARCH_FUNCTIONALITY',1);
  54 +}
  55 +unset($major); unset($minor); unset($fix);
  56 +
  57 +if (defined('HAS_SEARCH_FUNCTIONALITY'))
  58 +{
  59 + require_once(KT_DIR . '/search2/search/search.inc.php');
  60 +}
50 61  
51 62 // TODO: Test getting files/metadata based on versioning works and implementation is consistent.
52 63  
... ... @@ -106,6 +117,8 @@ class KTWebService
106 117 var $namespace;
107 118  
108 119 var $mustDebug;
  120 + var $version;
  121 + var $ktapi;
109 122  
110 123  
111 124  
... ... @@ -114,13 +127,9 @@ class KTWebService
114 127 // Caching was giving some problems, so disable it.
115 128  
116 129 $config = &KTConfig::getSingleton();
  130 + $this->version = $config->get('webservice/version', 2);
117 131 $this->mustDebug = $config->get('webservice/debug', false);
118   - $cache_enabled = $config->get('cache/cacheEnabled');
119   - if ($cache_enabled)
120   - {
121   - $this->error('Cache is enabled. This is likely to cause problems!', 'constructor');
122   - }
123   - $config->setns('cache','cacheEnabled',false);
  132 + $this->ktapi = null;
124 133  
125 134 $this->namespace = 'KnowledgeTree';
126 135  
... ... @@ -140,6 +149,11 @@ class KTWebService
140 149 'full_path' => 'string',
141 150 );
142 151  
  152 + if ($this->version >= 2)
  153 + {
  154 + $this->__typedef["{urn:$this->namespace}kt_folder_detail"]['created_by'] = 'string';
  155 + }
  156 +
143 157 $this->__typedef["{urn:$this->namespace}kt_folder_item"] =
144 158 array(
145 159 'id' => 'int',
... ... @@ -196,10 +210,43 @@ class KTWebService
196 210 'workflow_state' => 'string',
197 211 'checkout_by' => 'string',
198 212 'full_path' => 'string',
199   - // 'metadata' => "{urn:$this->namespace}kt_metadata_fieldsets",
200   - // 'owner' => 'string',
201 213 );
202 214  
  215 + if ($this->version >= 2)
  216 + {
  217 + $this->__typedef["{urn:$this->namespace}kt_document_detail"] =
  218 + array(
  219 + 'status_code'=>'int',
  220 + 'message'=>'string',
  221 + 'title' => 'string',
  222 + 'document_type' => 'string',
  223 + 'version' => 'string',
  224 + 'filename' => 'string',
  225 + 'created_date' => 'string',
  226 + 'created_by' => 'string',
  227 + 'modified_date' => 'string',
  228 + 'modified_by' => 'string',
  229 + 'document_id' => 'int',
  230 + 'folder_id' => 'int',
  231 + 'workflow' => 'string',
  232 + 'workflow_state' => 'string',
  233 + //'checkout_by' => 'string',
  234 + 'full_path' => 'string',
  235 + 'owner'=>'string',
  236 + 'is_immutable'=>'boolean',
  237 + 'checked_out_date'=>'string',
  238 + 'checked_out_by'=>'string',
  239 + 'metadata' => "{urn:$this->namespace}kt_metadata_fieldsets",
  240 + 'links' => "{urn:$this->namespace}kt_linked_documents",
  241 + 'transitions' => "{urn:$this->namespace}kt_workflow_transitions",
  242 + 'version_history' => "{urn:$this->namespace}kt_document_version_history",
  243 + 'transaction_history' => "{urn:$this->namespace}kt_document_transaction_history",
  244 + );
  245 + }
  246 +
  247 + if (defined('HAS_SEARCH_FUNCTIONALITY'))
  248 + {
  249 +
203 250 $this->__typedef["{urn:$this->namespace}kt_search_result_item"] =
204 251 array(
205 252 'document_id' => 'int',
... ... @@ -221,7 +268,7 @@ class KTWebService
221 268 'modified_date' => 'string',
222 269 'checked_out_by' => 'string',
223 270 'checked_out_date' => 'string',
224   - 'is_immutable' => 'bool',
  271 + 'is_immutable' => 'boolean',
225 272 'status' => 'string',
226 273 );
227 274  
... ... @@ -238,6 +285,24 @@ class KTWebService
238 285 'message' => 'string',
239 286 'hits' => "{urn:$this->namespace}kt_search_results" ,
240 287 );
  288 + }
  289 +
  290 + if ($this->version >= 2)
  291 + {
  292 +
  293 + $this->__typedef["{urn:$this->namespace}kt_sysdata_item"] =
  294 + array(
  295 + 'name' => 'string',
  296 + 'value' => 'string'
  297 + );
  298 +
  299 + $this->__typedef["{urn:$this->namespace}kt_sysdata"] =
  300 + array(
  301 + array(
  302 + 'item' => "{urn:$this->namespace}kt_sysdata_item"
  303 + )
  304 + );
  305 + }
241 306  
242 307 $this->__typedef["{urn:$this->namespace}kt_metadata_selection_item"] =
243 308 array(
... ... @@ -314,8 +379,7 @@ class KTWebService
314 379 'username'=>'string',
315 380 'version' => 'string',
316 381 'comment' => 'string',
317   - 'datetime' => 'string',
318   -
  382 + 'datetime' => 'string'
319 383 );
320 384  
321 385 $this->__typedef["{urn:$this->namespace}kt_linked_document"] =
... ... @@ -325,8 +389,7 @@ class KTWebService
325 389 'size' => 'int',
326 390 'workflow' => 'string',
327 391 'workflow_state' => 'string',
328   - 'link_type' => 'string',
329   -
  392 + 'link_type' => 'string'
330 393 );
331 394  
332 395 $this->__typedef["{urn:$this->namespace}kt_linked_documents"] =
... ... @@ -340,7 +403,7 @@ class KTWebService
340 403 array(
341 404 'status_code'=>'int',
342 405 'message'=>'string',
343   - 'parent_document_id' => 'string',
  406 + 'parent_document_id' => 'int',
344 407 'links' => "{urn:$this->namespace}kt_linked_documents"
345 408 );
346 409  
... ... @@ -416,11 +479,14 @@ class KTWebService
416 479 );
417 480  
418 481 /* methods */
  482 + if (defined('HAS_SEARCH_FUNCTIONALITY'))
  483 + {
419 484  
420   - $this->__dispatch_map['search'] =
421   - array('in' => array('session_id' => 'string', 'search'=>'string' ,'options'=>'string'),
422   - 'out' => array('return' => "{urn:$this->namespace}kt_search_response" ),
423   - );
  485 + $this->__dispatch_map['search'] = array(
  486 + 'in' => array('session_id' => 'string', 'search'=>'string' ,'options'=>'string'),
  487 + 'out' => array('return' => "{urn:$this->namespace}kt_search_response" ),
  488 + );
  489 + }
424 490  
425 491 // login
426 492 $this->__dispatch_map['login'] =
... ... @@ -465,6 +531,17 @@ class KTWebService
465 531 'out' => array('return' => "{urn:$this->namespace}kt_folder_detail"),
466 532 );
467 533  
  534 + if ($this->version >=2)
  535 + {
  536 + // create_folder
  537 + $this->__dispatch_map['add_folder'] =
  538 + array('in' => array('session_id'=>'string','folder_id'=>'int','folder_name' =>'string'),
  539 + 'out' => array('return' => "{urn:$this->namespace}kt_folder_detail"),
  540 + 'alias'=>'create_folder'
  541 + );
  542 + }
  543 +
  544 +
468 545 // delete_folder
469 546 $this->__dispatch_map['delete_folder'] =
470 547 array('in' => array('session_id'=>'string','folder_id'=>'int','reason' =>'string'),
... ... @@ -509,11 +586,17 @@ class KTWebService
509 586 );
510 587  
511 588 // get_document_detail
512   - $this->__dispatch_map['get_document_detail'] =
513   - array('in' => array('session_id' => 'string', 'document_id' => 'int' ),
514   - 'out' => array('return' => "{urn:$this->namespace}kt_document_detail"),
  589 + $this->__dispatch_map['get_document_detail'] = array(
  590 + 'in' => array('session_id' => 'string', 'document_id' => 'int' ),
  591 + 'out' => array('return' => "{urn:$this->namespace}kt_document_detail"),
515 592 );
516 593  
  594 + if ($this->version >= 2)
  595 + {
  596 + $this->__dispatch_map['get_document_detail']['in'] = array('session_id' => 'string', 'document_id' => 'int', 'detail'=>'string' );
  597 + }
  598 +
  599 +
517 600 // checkin_document
518 601 $this->__dispatch_map['checkin_document'] =
519 602 array('in' => array('session_id'=>'string','document_id'=>'int','filename'=>'string','reason' =>'string','tempfilename' =>'string', 'major_update'=>'boolean' ),
... ... @@ -533,6 +616,20 @@ class KTWebService
533 616 'alias' => 'checkin_small_document'
534 617 );
535 618  
  619 + if ($this->version >= 2)
  620 + {
  621 + $this->__dispatch_map['checkin_base64_document_with_metadata'] =
  622 + array('in' => array('session_id'=>'string','document_id'=>'int','filename'=>'string','reason' =>'string','base64' =>'string', 'major_update'=>'boolean', 'metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets",'sysdata'=>"{urn:$this->namespace}kt_sysdata" ),
  623 + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ),
  624 + 'alias'=>'checkin_small_document_with_metadata'
  625 + );
  626 + $this->__dispatch_map['checkin_document_with_metadata'] =
  627 + array('in' => array('session_id'=>'string','document_id'=>'int','filename'=>'string','reason' =>'string','tempfilename' =>'string', 'major_update'=>'boolean', 'metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets",'sysdata'=>"{urn:$this->namespace}kt_sysdata" ),
  628 + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" )
  629 + );
  630 +
  631 + }
  632 +
536 633 // add_document
537 634 $this->__dispatch_map['add_document'] =
538 635 array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','tempfilename' =>'string' ),
... ... @@ -553,6 +650,23 @@ class KTWebService
553 650  
554 651 );
555 652  
  653 + if ($this->version >= 2)
  654 + {
  655 + $this->__dispatch_map['add_base64_document_with_metadata'] =
  656 + array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','base64' =>'string', 'metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets",'sysdata'=>"{urn:$this->namespace}kt_sysdata" ),
  657 + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ),
  658 + 'alias'=>'add_small_document_with_metadata'
  659 + );
  660 +
  661 + $this->__dispatch_map['add_document_with_metadata'] =
  662 + array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','tempfilename' =>'string', 'metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets",'sysdata'=>"{urn:$this->namespace}kt_sysdata" ),
  663 + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" )
  664 + );
  665 +
  666 +
  667 + }
  668 +
  669 +
556 670  
557 671 // get_document_detail_by_name
558 672 $this->__dispatch_map['get_document_detail_by_name'] =
... ... @@ -560,18 +674,48 @@ class KTWebService
560 674 'out' => array('return' => "{urn:$this->namespace}kt_document_detail"),
561 675 );
562 676  
  677 + if ($this->version >= 2)
  678 + {
  679 + $this->__dispatch_map['get_document_detail_by_name']['in'] = array('session_id' => 'string', 'folder_id'=>'int', 'document_name' => 'string', 'what'=>'string', 'detail'=>'string' );
  680 +
  681 + $this->__dispatch_map['get_document_detail_by_title'] = array(
  682 + 'in' => array('session_id' => 'string', 'folder_id'=>'int', 'title' => 'string', 'detail'=>'string' ),
  683 + 'out' => array('return' => "{urn:$this->namespace}kt_document_detail"),
  684 + );
  685 +
  686 + $this->__dispatch_map['get_document_detail_by_filename'] = array(
  687 + 'in' => array('session_id' => 'string', 'folder_id'=>'int', 'filename' => 'string', 'detail'=>'string' ),
  688 + 'out' => array('return' => "{urn:$this->namespace}kt_document_detail"),
  689 + );
  690 + }
  691 +
563 692 // checkout_document
564 693 $this->__dispatch_map['checkout_document'] =
565 694 array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string'),
566 695 'out' => array('return' => "{urn:$this->namespace}kt_response" ),
567 696 );
568 697  
  698 + if ($this->version >= 2)
  699 + {
  700 + $this->__dispatch_map['checkout_document'] =
  701 + array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string','download'=>'boolean'),
  702 + 'out' => array('return' => "{urn:$this->namespace}kt_document_detail" ),
  703 + );
  704 + }
  705 +
  706 +
569 707 // checkout_small_document
570 708 $this->__dispatch_map['checkout_small_document'] =
571 709 array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string','download' => 'boolean'),
572 710 'out' => array('return' => "{urn:$this->namespace}kt_response" ),
573 711 );
574 712  
  713 + if ($this->version >= 2)
  714 + {
  715 + $this->__dispatch_map['checkout_small_document']['out'] = array('return' => "{urn:$this->namespace}kt_document_detail" );
  716 + }
  717 +
  718 +
575 719 // checkout_base64_document
576 720 $this->__dispatch_map['checkout_base64_document'] =
577 721 array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string','download' => 'boolean'),
... ... @@ -579,12 +723,25 @@ class KTWebService
579 723 'alias' => 'checkout_small_document'
580 724 );
581 725  
  726 + if ($this->version >= 2)
  727 + {
  728 + $this->__dispatch_map['checkout_base64_document']['out'] = array('return' => "{urn:$this->namespace}kt_document_detail" );
  729 + }
  730 +
  731 +
582 732 // undo_document_checkout
583 733 $this->__dispatch_map['undo_document_checkout'] =
584 734 array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string'),
585 735 'out' => array('return' => "{urn:$this->namespace}kt_response" ),
586 736 );
587 737  
  738 + if ($this->version >= 2)
  739 + {
  740 + $this->__dispatch_map['undo_document_checkout']['out'] = array('return' => "{urn:$this->namespace}kt_document_detail" );
  741 + }
  742 +
  743 +
  744 +
588 745 // download_document
589 746 $this->__dispatch_map['download_document'] =
590 747 array('in' => array('session_id'=>'string','document_id'=>'int' ),
... ... @@ -617,28 +774,51 @@ class KTWebService
617 774 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ),
618 775 );
619 776  
  777 + if ($this->version >= 2)
  778 + {
  779 + $this->__dispatch_map['change_document_owner']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" );
  780 + }
  781 +
  782 +
620 783 // copy_document
621 784 $this->__dispatch_map['copy_document'] =
622 785 array('in' => array('session_id'=>'string','document_id'=>'int','folder_id'=>'int','reason'=>'string','newtitle'=>'string','newfilename'=>'string'),
623 786 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ),
624 787 );
  788 + if ($this->version >= 2)
  789 + {
  790 + $this->__dispatch_map['copy_document']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" );
  791 + }
625 792  
626 793 // move_document
627 794 $this->__dispatch_map['move_document'] =
628 795 array('in' => array('session_id'=>'string','document_id'=>'int','folder_id'=>'int','reason'=>'string','newtitle'=>'string','newfilename'=>'string'),
629 796 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ),
630 797 );
  798 + if ($this->version >= 2)
  799 + {
  800 + $this->__dispatch_map['move_document']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" );
  801 + }
  802 +
631 803 // rename_document_title
632 804 $this->__dispatch_map['rename_document_title'] =
633 805 array('in' => array('session_id'=>'string','document_id'=>'int', 'newtitle'=>'string' ),
634 806 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ),
635 807 );
636   -
  808 + if ($this->version >= 2)
  809 + {
  810 + $this->__dispatch_map['rename_document_title']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" );
  811 + }
637 812 // rename_document_filename
638 813 $this->__dispatch_map['rename_document_filename'] =
639 814 array('in' => array('session_id'=>'string','document_id'=>'int', 'newfilename'=>'string' ),
640 815 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ),
641 816 );
  817 + if ($this->version >= 2)
  818 + {
  819 + $this->__dispatch_map['rename_document_filename']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" );
  820 + }
  821 +
642 822  
643 823 // change_document_type
644 824 $this->__dispatch_map['change_document_type'] =
... ... @@ -646,23 +826,51 @@ class KTWebService
646 826 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ),
647 827 );
648 828  
  829 + if ($this->version >= 2)
  830 + {
  831 + $this->__dispatch_map['change_document_type']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" );
  832 + }
  833 +
649 834 // start_document_workflow
650 835 $this->__dispatch_map['start_document_workflow'] =
651 836 array('in' => array('session_id'=>'string','document_id'=>'int', 'workflow'=>'string' ),
652 837 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ),
653 838 );
  839 +
  840 + if ($this->version >= 2)
  841 + {
  842 + $this->__dispatch_map['start_document_workflow']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" );
  843 + }
  844 +
654 845 // delete_document_workflow
655 846 $this->__dispatch_map['delete_document_workflow'] =
656 847 array('in' => array('session_id'=>'string','document_id'=>'int' ),
657   - 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ),
  848 + 'out' => array( 'return' => "{urn:$this->namespace}kt_response" )
658 849 );
659 850  
  851 + if ($this->version >= 2)
  852 + {
  853 + $this->__dispatch_map['delete_document_workflow']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" );
  854 +
  855 + // stop_document_workflow
  856 + $this->__dispatch_map['stop_document_workflow'] =
  857 + array('in' => array('session_id'=>'string','document_id'=>'int' ),
  858 + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ),
  859 + 'alias'=>'delete_document_workflow'
  860 + );
  861 + }
  862 +
660 863 // perform_document_workflow_transition
661 864 $this->__dispatch_map['perform_document_workflow_transition'] =
662 865 array('in' => array('session_id'=>'string','document_id'=>'int','transition'=>'string','reason'=>'string' ),
663 866 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ),
664 867 );
665 868  
  869 + if ($this->version >= 2)
  870 + {
  871 + $this->__dispatch_map['perform_document_workflow_transition']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" );
  872 + }
  873 +
666 874 // get_document_metadata
667 875 $this->__dispatch_map['get_document_metadata'] =
668 876 array('in' => array('session_id'=>'string','document_id'=>'int' ),
... ... @@ -676,10 +884,20 @@ class KTWebService
676 884 );
677 885 //update_document_metadata
678 886 $this->__dispatch_map['update_document_metadata'] =
679   - array('in' => array('session_id'=>'string','document_id'=>'int','metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets" ),
  887 + array('in' => array('session_id'=>'string','document_id'=>'int','metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets" ),
680 888 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ),
681 889 );
682 890  
  891 + if ($this->version >= 2)
  892 + {
  893 + $this->__dispatch_map['update_document_metadata'] =
  894 + array('in' => array('session_id'=>'string','document_id'=>'int','metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets", 'sysdata'=>"{urn:$this->namespace}kt_sysdata" ),
  895 + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" )
  896 + );
  897 +
  898 +
  899 + }
  900 +
683 901  
684 902 //get_document_workflow_transitions
685 903 $this->__dispatch_map['get_document_workflow_transitions'] =
... ... @@ -728,9 +946,10 @@ class KTWebService
728 946  
729 947 }
730 948  
731   - function debug($msg, $function = null)
  949 + function debug($msg, $function = null, $level=0)
732 950 {
733   - if ($this->mustDebug)
  951 + if ($this->mustDebug === false) return;
  952 + if ($this->mustDebug >= $level)
734 953 {
735 954 global $default;
736 955 if (!is_null($function))
... ... @@ -763,6 +982,11 @@ class KTWebService
763 982 */
764 983 function &get_ktapi($session_id)
765 984 {
  985 + if (!is_null($this->ktapi))
  986 + {
  987 + return $this->ktapi;
  988 + }
  989 +
766 990 $kt = new KTAPI();
767 991  
768 992 $session = $kt->get_active_session($session_id, null);
... ... @@ -776,6 +1000,7 @@ class KTWebService
776 1000  
777 1001 return $response;
778 1002 }
  1003 + $this->ktapi = $kt;
779 1004 return $kt;
780 1005 }
781 1006  
... ... @@ -1368,9 +1593,9 @@ class KTWebService
1368 1593 * @param int $document_id
1369 1594 * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS
1370 1595 */
1371   - function get_document_detail($session_id, $document_id)
  1596 + function get_document_detail($session_id, $document_id, $detail='')
1372 1597 {
1373   - $this->debug("get_document_detail('$session_id',$document_id)");
  1598 + $this->debug("get_document_detail('$session_id',$document_id,'$detail')");
1374 1599 $kt = &$this->get_ktapi($session_id );
1375 1600 if (is_array($kt))
1376 1601 {
... ... @@ -1389,6 +1614,7 @@ class KTWebService
1389 1614 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response);
1390 1615 }
1391 1616  
  1617 + $detailstr = $detail;
1392 1618 $detail = $document->get_detail();
1393 1619 if (PEAR::isError($detail))
1394 1620 {
... ... @@ -1402,9 +1628,62 @@ class KTWebService
1402 1628  
1403 1629 $detail['status_code']=KTWS_SUCCESS;
1404 1630 $detail['message']='';
  1631 +
  1632 + if ($this->version >= 2)
  1633 + {
  1634 + $detail['metadata'] = array();
  1635 + $detail['links'] = array();
  1636 + $detail['transitions'] = array();
  1637 + $detail['version_history'] = array();
  1638 + $detail['transaction_history'] = array();
  1639 +
  1640 +
  1641 + if (stripos($detailstr,'M') !== false)
  1642 + {
  1643 + $response = $this->get_document_metadata($session_id, $document_id);
  1644 + $detail['metadata'] = $response->value['metadata'];
  1645 + }
  1646 +
  1647 + if (stripos($detailstr,'L') !== false)
  1648 + {
  1649 + $response = $this->get_document_metadata($session_id, $document_id);
  1650 + $detail['links'] = $response->value['links'];
  1651 + }
  1652 +
  1653 + if (stripos($detailstr,'T') !== false)
  1654 + {
  1655 + $response = $this->get_document_workflow_transitions($session_id, $document_id);
  1656 + $detail['transitions'] = $response->value['transitions'];
  1657 + }
  1658 +
  1659 + if (stripos($detailstr,'V') !== false)
  1660 + {
  1661 + $response = $this->get_document_version_history($session_id, $document_id);
  1662 + $detail['version_history'] = $response->value['history'];
  1663 + }
  1664 +
  1665 + if (stripos($detailstr,'H') !== false)
  1666 + {
  1667 + $response = $this->get_document_transaction_history($session_id, $document_id);
  1668 + $detail['transaction_history'] = $response->value['history'];
  1669 + }
  1670 +
  1671 + }
  1672 +
1405 1673 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $detail);
1406 1674 }
1407 1675  
  1676 + function get_document_detail_by_filename($session_id, $folder_id, $filename, $detail='')
  1677 + {
  1678 + return $this->get_document_detail_by_name($session_id, $folder_id, $filename, 'F', $detail);
  1679 + }
  1680 +
  1681 + function get_document_detail_by_title($session_id, $folder_id, $title, $detail='')
  1682 + {
  1683 + return $this->get_document_detail_by_name($session_id, $folder_id, $title, 'T', $detail);
  1684 + }
  1685 +
  1686 +
1408 1687 /**
1409 1688 * Returns document detail given a document name which could include a full path.
1410 1689 *
... ... @@ -1413,9 +1692,9 @@ class KTWebService
1413 1692 * @param string @what
1414 1693 * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS
1415 1694 */
1416   - function get_document_detail_by_name($session_id, $document_name, $what='T')
  1695 + function get_document_detail_by_name($session_id, $folder_id, $document_name, $what='T', $detail='')
1417 1696 {
1418   - $this->debug("get_document_detail_by_name('$session_id','$document_name','$what')");
  1697 + $this->debug("get_document_detail_by_name('$session_id','$document_name','$what','$detail')");
1419 1698 $response=array(
1420 1699 'status_code'=>KTWS_ERR_INVALID_FOLDER,
1421 1700 'message'=>''
... ... @@ -1439,10 +1718,11 @@ class KTWebService
1439 1718 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $kt);
1440 1719 }
1441 1720  
1442   - $root = &$kt->get_root_folder();
  1721 + if ($folder_id < 1) $folder_id = 1;
  1722 + $root = &$kt->get_folder_by_id($folder_id);
1443 1723 if (PEAR::isError($root))
1444 1724 {
1445   - $this->debug("get_document_detail_by_name - cannot get root folder - " . $root->getMessage(), $session_id);
  1725 + $this->debug("get_document_detail_by_name - cannot get root folder - folder_id = $folder_id - " . $root->getMessage(), $session_id);
1446 1726  
1447 1727 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response);
1448 1728 }
... ... @@ -1466,6 +1746,8 @@ class KTWebService
1466 1746 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response);
1467 1747 }
1468 1748  
  1749 + $detailstr = $detail;
  1750 +
1469 1751 $detail = $document->get_detail();
1470 1752 if (PEAR::isError($detail))
1471 1753 {
... ... @@ -1480,6 +1762,47 @@ class KTWebService
1480 1762 $detail['status_code']=KTWS_SUCCESS;
1481 1763 $detail['message']='';
1482 1764  
  1765 +
  1766 + if ($this->version >= 2)
  1767 + {
  1768 +
  1769 + $detail['metadata'] = array();
  1770 + $detail['links'] = array();
  1771 + $detail['transitions'] = array();
  1772 + $detail['version_history'] = array();
  1773 + $detail['transaction_history'] = array();
  1774 +
  1775 + if (stripos($detailstr,'M') !== false)
  1776 + {
  1777 + $response = $this->get_document_metadata($session_id, $document_id);
  1778 + $detail['metadata'] = $response->value['metadata'];
  1779 + }
  1780 +
  1781 + if (stripos($detailstr,'L') !== false)
  1782 + {
  1783 + $response = $this->get_document_metadata($session_id, $document_id);
  1784 + $detail['links'] = $response->value['links'];
  1785 + }
  1786 +
  1787 + if (stripos($detailstr,'T') !== false)
  1788 + {
  1789 + $response = $this->get_document_workflow_transitions($session_id, $document_id);
  1790 + $detail['transitions'] = $response->value['transitions'];
  1791 + }
  1792 +
  1793 + if (stripos($detailstr,'V') !== false)
  1794 + {
  1795 + $response = $this->get_document_version_history($session_id, $document_id);
  1796 + $detail['version_history'] = $response->value['history'];
  1797 + }
  1798 +
  1799 + if (stripos($detailstr,'H') !== false)
  1800 + {
  1801 + $response = $this->get_document_transaction_history($session_id, $document_id);
  1802 + $detail['transaction_history'] = $response->value['history'];
  1803 + }
  1804 + }
  1805 +
1483 1806 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $detail);
1484 1807 }
1485 1808  
... ... @@ -1552,6 +1875,76 @@ class KTWebService
1552 1875 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $detail);
1553 1876 }
1554 1877  
  1878 + function add_small_document_with_metadata($session_id, $folder_id, $title, $filename, $documenttype, $base64, $metadata, $sysdata)
  1879 + {
  1880 + $add_result = $this->add_small_document($session_id, $folder_id, $title, $filename, $documenttype, $base64);
  1881 +
  1882 + $status_code = $add_result->value['status_code'];
  1883 + if ($status_code != 0)
  1884 + {
  1885 + return $add_result;
  1886 + }
  1887 + $document_id = $add_result->value['document_id'];
  1888 +
  1889 + $update_result = $this->update_document_metadata($session_id, $document_id, $metadata, $sysdata);
  1890 + $status_code = $update_result->value['status_code'];
  1891 + if ($status_code != 0)
  1892 + {
  1893 + return $update_result;
  1894 + }
  1895 +
  1896 + $kt = &$this->get_ktapi($session_id );
  1897 + if (is_array($kt))
  1898 + {
  1899 + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $kt);
  1900 + }
  1901 +
  1902 + $document = $kt->get_document_by_id($document_id);
  1903 + $result = $document->mergeWithLastMetadataVersion();
  1904 + if (PEAR::isError($result))
  1905 + {
  1906 + // not much we can do, maybe just log!
  1907 + }
  1908 +
  1909 + return $update_result;
  1910 + }
  1911 +
  1912 + function add_document_with_metadata($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $metadata, $sysdata)
  1913 + {
  1914 + $add_result = $this->add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename);
  1915 +
  1916 + $status_code = $add_result->value['status_code'];
  1917 + if ($status_code != 0)
  1918 + {
  1919 + return $add_result;
  1920 + }
  1921 + $document_id = $add_result->value['document_id'];
  1922 +
  1923 + $update_result = $this->update_document_metadata($session_id, $document_id, $metadata, $sysdata);
  1924 + $status_code = $update_result->value['status_code'];
  1925 + if ($status_code != 0)
  1926 + {
  1927 + return $update_result;
  1928 + }
  1929 +
  1930 + $kt = &$this->get_ktapi($session_id );
  1931 + if (is_array($kt))
  1932 + {
  1933 + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $kt);
  1934 + }
  1935 +
  1936 + $document = $kt->get_document_by_id($document_id);
  1937 + $result = $document->mergeWithLastMetadataVersion();
  1938 + if (PEAR::isError($result))
  1939 + {
  1940 + // not much we can do, maybe just log!
  1941 + }
  1942 +
  1943 + return $update_result;
  1944 + }
  1945 +
  1946 +
  1947 +
1555 1948 /**
1556 1949 * Adds a document to the repository.
1557 1950 *
... ... @@ -1705,11 +2098,78 @@ class KTWebService
1705 2098 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response);
1706 2099 }
1707 2100  
1708   - $response['status_code'] = KTWS_SUCCESS;
1709   -
1710   - return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response);
  2101 + // get status after checkin
  2102 + return $this->get_document_detail($session_id, $document_id);
1711 2103 }
1712 2104  
  2105 +
  2106 + function checkin_small_document_with_metadata($session_id, $document_id, $filename, $reason, $base64, $major_update, $metadata, $sysdata)
  2107 + {
  2108 + $add_result = $this->checkin_small_document($session_id, $document_id, $filename, $reason, $base64, $major_update);
  2109 +
  2110 + $status_code = $add_result->value['status_code'];
  2111 + if ($status_code != 0)
  2112 + {
  2113 + return $add_result;
  2114 + }
  2115 +
  2116 + $update_result = $this->update_document_metadata($session_id, $document_id, $metadata, $sysdata);
  2117 + $status_code = $update_result->value['status_code'];
  2118 + if ($status_code != 0)
  2119 + {
  2120 + return $update_result;
  2121 + }
  2122 +
  2123 + $kt = &$this->get_ktapi($session_id );
  2124 + if (is_array($kt))
  2125 + {
  2126 + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $kt);
  2127 + }
  2128 +
  2129 + $document = $kt->get_document_by_id($document_id);
  2130 + $result = $document->mergeWithLastMetadataVersion();
  2131 + if (PEAR::isError($result))
  2132 + {
  2133 + // not much we can do, maybe just log!
  2134 + }
  2135 +
  2136 + return $update_result;
  2137 + }
  2138 +
  2139 + function checkin_document_with_metadata($session_id, $document_id, $filename, $reason, $tempfilename, $major_update, $metadata, $sysdata)
  2140 + {
  2141 + $add_result = $this->checkin_document($session_id, $document_id, $filename, $reason, $tempfilename, $major_update);
  2142 +
  2143 + $status_code = $add_result->value['status_code'];
  2144 + if ($status_code != 0)
  2145 + {
  2146 + return $add_result;
  2147 + }
  2148 +
  2149 + $update_result = $this->update_document_metadata($session_id, $document_id, $metadata, $sysdata);
  2150 + $status_code = $update_result->value['status_code'];
  2151 + if ($status_code != 0)
  2152 + {
  2153 + return $update_result;
  2154 + }
  2155 +
  2156 + $kt = &$this->get_ktapi($session_id );
  2157 + if (is_array($kt))
  2158 + {
  2159 + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $kt);
  2160 + }
  2161 +
  2162 + $document = $kt->get_document_by_id($document_id);
  2163 + $result = $document->mergeWithLastMetadataVersion();
  2164 + if (PEAR::isError($result))
  2165 + {
  2166 + // not much we can do, maybe just log!
  2167 + }
  2168 +
  2169 + return $update_result;
  2170 + }
  2171 +
  2172 +
1713 2173 /**
1714 2174 * Does a document checkin.
1715 2175 *
... ... @@ -1795,10 +2255,8 @@ class KTWebService
1795 2255 $this->debug("checkin_small_document - cannot checkin document - " . $result->getMessage(), $session_id);
1796 2256 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response);
1797 2257 }
1798   -
1799   - $response['status_code'] = KTWS_SUCCESS;
1800   -
1801   - return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response);
  2258 + // get status after checkin
  2259 + return $this->get_document_detail($session_id, $document_id);
1802 2260 }
1803 2261  
1804 2262 /**
... ... @@ -1807,9 +2265,9 @@ class KTWebService
1807 2265 * @param string $session_id
1808 2266 * @param int $document_id
1809 2267 * @param string $reason
1810   - * @return kt_response. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER or KTWS_SUCCESS
  2268 + * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER or KTWS_SUCCESS
1811 2269 */
1812   - function checkout_document($session_id, $document_id, $reason)
  2270 + function checkout_document($session_id, $document_id, $reason,$download=true)
1813 2271 {
1814 2272 $this->debug("checkout_document('$session_id',$document_id,'$reason')");
1815 2273  
... ... @@ -1842,14 +2300,26 @@ class KTWebService
1842 2300  
1843 2301 $session = &$kt->get_session();
1844 2302  
1845   - $download_manager = new KTDownloadManager();
1846   - $download_manager->set_session($session->session);
1847   - $download_manager->cleanup();
1848   - $url = $download_manager->allow_download($document);
  2303 + $url = '';
  2304 + if ($download)
  2305 + {
  2306 + $download_manager = new KTDownloadManager();
  2307 + $download_manager->set_session($session->session);
  2308 + $download_manager->cleanup();
  2309 + $url = $download_manager->allow_download($document);
  2310 + }
1849 2311  
1850 2312 $response['status_code'] = KTWS_SUCCESS;
1851 2313 $response['message'] = $url;
1852 2314  
  2315 + if ($this->version >= 2)
  2316 + {
  2317 + $result = $this->get_document_detail($session_id, $document_id);
  2318 + $result->value['message'] = $url;
  2319 +
  2320 + return $result;
  2321 + }
  2322 +
1853 2323 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
1854 2324 }
1855 2325  
... ... @@ -1860,7 +2330,7 @@ class KTWebService
1860 2330 * @param int $document_id
1861 2331 * @param string $reason
1862 2332 * @param boolean $download
1863   - * @return kt_response status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER or KTWS_SUCCESS
  2333 + * @return kt_document_detail status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER or KTWS_SUCCESS
1864 2334 */
1865 2335 function checkout_small_document($session_id, $document_id, $reason, $download)
1866 2336 {
... ... @@ -1916,6 +2386,15 @@ class KTWebService
1916 2386 $response['status_code'] = KTWS_SUCCESS;
1917 2387 $response['message'] = $content;
1918 2388  
  2389 + if ($this->version >= 2)
  2390 + {
  2391 + $result = $this->get_document_detail($session_id, $document_id);
  2392 + $result->value['message'] = $content;
  2393 +
  2394 + return $result;
  2395 + }
  2396 +
  2397 +
1919 2398 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
1920 2399 }
1921 2400  
... ... @@ -1925,7 +2404,7 @@ class KTWebService
1925 2404 * @param string $session_id
1926 2405 * @param int $document_id
1927 2406 * @param string $reason
1928   - * @return kt_response. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS
  2407 + * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS
1929 2408 */
1930 2409 function undo_document_checkout($session_id, $document_id, $reason)
1931 2410 {
... ... @@ -1962,6 +2441,11 @@ class KTWebService
1962 2441  
1963 2442 $response['status_code'] = KTWS_SUCCESS;
1964 2443  
  2444 + if ($this->version >= 2)
  2445 + {
  2446 + return $this->get_document_detail($session_id, $document_id);
  2447 + }
  2448 +
1965 2449 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
1966 2450 }
1967 2451  
... ... @@ -2129,16 +2613,23 @@ class KTWebService
2129 2613 * @param string $session_id
2130 2614 * @param int $document_id
2131 2615 * @param string $documenttype
2132   - * @return kt_response
  2616 + * @return kt_document_detail
2133 2617 */
2134 2618 function change_document_type($session_id, $document_id, $documenttype)
2135 2619 {
2136 2620 $this->debug("change_document_type('$session_id',$document_id,'$documenttype')");
2137 2621  
2138 2622 $kt = &$this->get_ktapi($session_id );
  2623 +
  2624 + $responseType = 'kt_response';
  2625 + if ($this->version >= 2)
  2626 + {
  2627 + $responseType = 'kt_document_detail';
  2628 + }
  2629 +
2139 2630 if (is_array($kt))
2140 2631 {
2141   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
  2632 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
2142 2633 }
2143 2634 $response=array(
2144 2635 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
... ... @@ -2151,7 +2642,7 @@ class KTWebService
2151 2642 $response['message'] = $document->getMessage();
2152 2643  
2153 2644 $this->debug("change_document_type - cannot get documentid $document_id - " . $document->getMessage(), $session_id);
2154   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2645 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2155 2646 }
2156 2647  
2157 2648 $result = $document->change_document_type($documenttype);
... ... @@ -2160,11 +2651,16 @@ class KTWebService
2160 2651 $response['message'] = $result->getMessage();
2161 2652 $this->debug("change_document_type - cannot change type - " . $result->getMessage(), $session_id);
2162 2653  
2163   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2654 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2164 2655 }
2165 2656 $response['status_code'] = KTWS_SUCCESS;
2166 2657  
2167   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2658 + if ($this->version >= 2)
  2659 + {
  2660 + return $this->get_document_detail($session_id, $document_id);
  2661 + }
  2662 +
  2663 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2168 2664 }
2169 2665  
2170 2666 /**
... ... @@ -2176,7 +2672,7 @@ class KTWebService
2176 2672 * @param string $reason
2177 2673 * @param string $newtitle
2178 2674 * @param string $newfilename
2179   - * @return kt_response
  2675 + * @return kt_document_detail
2180 2676 */
2181 2677 function copy_document($session_id,$document_id,$folder_id,$reason,$newtitle,$newfilename)
2182 2678 {
... ... @@ -2217,6 +2713,11 @@ class KTWebService
2217 2713 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
2218 2714 }
2219 2715 $response['status_code'] = KTWS_SUCCESS;
  2716 + if ($this->version >= 2)
  2717 + {
  2718 + $new_document_id = $result->documentid;
  2719 + return $this->get_document_detail($session_id, $new_document_id, '');
  2720 + }
2220 2721  
2221 2722 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
2222 2723 }
... ... @@ -2286,9 +2787,16 @@ class KTWebService
2286 2787 {
2287 2788 $this->debug("rename_document_title('$session_id',$document_id,'$newtitle')");
2288 2789 $kt = &$this->get_ktapi($session_id );
  2790 +
  2791 + $responseType = 'kt_response';
  2792 + if ($this->version >=2)
  2793 + {
  2794 + $responseType='kt_document_detail';
  2795 + }
  2796 +
2289 2797 if (is_array($kt))
2290 2798 {
2291   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
  2799 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
2292 2800 }
2293 2801 $response=array(
2294 2802 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
... ... @@ -2300,7 +2808,7 @@ class KTWebService
2300 2808 {
2301 2809 $response['message'] = $document->getMessage();
2302 2810 $this->debug("rename_document_title - cannot get documentid $document_id - " . $document->getMessage(), $session_id);
2303   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2811 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2304 2812 }
2305 2813  
2306 2814 $result = $document->rename($newtitle);
... ... @@ -2308,11 +2816,16 @@ class KTWebService
2308 2816 {
2309 2817 $response['message'] = $result->getMessage();
2310 2818 $this->debug("rename_document_title - cannot rename - " . $result->getMessage(), $session_id);
2311   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2819 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2312 2820 }
2313 2821 $response['status_code'] = KTWS_SUCCESS;
2314 2822  
2315   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2823 + if ($this->version >= 2)
  2824 + {
  2825 + return $this->get_document_detail($session_id, $document_id);
  2826 + }
  2827 +
  2828 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2316 2829 }
2317 2830  
2318 2831 /**
... ... @@ -2328,9 +2841,15 @@ class KTWebService
2328 2841 $this->debug("rename_document_filename('$session_id',$document_id,'$newfilename')");
2329 2842  
2330 2843 $kt = &$this->get_ktapi($session_id );
  2844 + $responseType = 'kt_response';
  2845 + if ($this->version >=2)
  2846 + {
  2847 + $responseType='kt_document_detail';
  2848 + }
  2849 +
2331 2850 if (is_array($kt))
2332 2851 {
2333   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
  2852 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
2334 2853 }
2335 2854 $response=array(
2336 2855 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
... ... @@ -2342,7 +2861,7 @@ class KTWebService
2342 2861 {
2343 2862 $response['message'] = $document->getMessage();
2344 2863 $this->debug("rename_document_filename - cannot get documetid $document_id - " . $document->getMessage(), $session_id);
2345   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2864 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2346 2865 }
2347 2866  
2348 2867 $result = $document->renameFile($newfilename);
... ... @@ -2350,11 +2869,16 @@ class KTWebService
2350 2869 {
2351 2870 $response['message'] = $result->getMessage();
2352 2871 $this->debug("rename_document_filename - cannot rename - " . $result->getMessage(), $session_id);
2353   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2872 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2354 2873 }
2355 2874 $response['status_code'] = KTWS_SUCCESS;
  2875 + if ($this->version >= 2)
  2876 + {
  2877 + return $this->get_document_detail($session_id, $document_id);
  2878 + }
2356 2879  
2357   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2880 +
  2881 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2358 2882 }
2359 2883  
2360 2884 /**
... ... @@ -2364,17 +2888,25 @@ class KTWebService
2364 2888 * @param int $document_id
2365 2889 * @param string $username
2366 2890 * @param string $reason
2367   - * @return kt_response. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS
  2891 + * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS
2368 2892 */
2369 2893 function change_document_owner($session_id, $document_id, $username, $reason)
2370 2894 {
2371 2895 $this->debug("change_document_owner('$session_id',$document_id,'$username','$reason')");
2372 2896  
2373 2897 $kt = &$this->get_ktapi($session_id );
  2898 +
  2899 + $responseType = 'kt_response';
  2900 + if ($this->version >= 2)
  2901 + {
  2902 + $responseType = 'kt_document_detail';
  2903 + }
  2904 +
2374 2905 if (is_array($kt))
2375 2906 {
2376   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
  2907 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
2377 2908 }
  2909 +
2378 2910 $response=array(
2379 2911 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2380 2912 'message'=>''
... ... @@ -2385,7 +2917,7 @@ class KTWebService
2385 2917 {
2386 2918 $response['message'] = $document->getMessage();
2387 2919 $this->debug("change_document_owner - cannot get documetid $document_id - " . $document->getMessage(), $session_id);
2388   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2920 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2389 2921 }
2390 2922  
2391 2923 $result = $document->change_owner($username, $reason);
... ... @@ -2393,11 +2925,16 @@ class KTWebService
2393 2925 {
2394 2926 $response['message'] = $result->getMessage();
2395 2927 $this->debug("change_document_owner - cannot change owner - " . $result->getMessage(), $session_id);
2396   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2928 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2397 2929 }
2398 2930 $response['status_code'] = KTWS_SUCCESS;
2399 2931  
2400   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2932 + if ($this->version >= 2)
  2933 + {
  2934 + return $this->get_document_detail($session_id, $document_id);
  2935 + }
  2936 +
  2937 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2401 2938 }
2402 2939  
2403 2940 /**
... ... @@ -2406,16 +2943,22 @@ class KTWebService
2406 2943 * @param string $session_id
2407 2944 * @param int $document_id
2408 2945 * @param string $workflow
2409   - * @return kt_response
  2946 + * @return kt_document_detail
2410 2947 */
2411 2948 function start_document_workflow($session_id,$document_id,$workflow)
2412 2949 {
2413 2950 $this->debug("start_document_workflow('$session_id',$document_id,'$workflow')");
2414 2951  
2415 2952 $kt = &$this->get_ktapi($session_id );
  2953 + $responseType = 'kt_response';
  2954 + if ($this->version >= 2)
  2955 + {
  2956 + $responseType = 'kt_document_detail';
  2957 + }
  2958 +
2416 2959 if (is_array($kt))
2417 2960 {
2418   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
  2961 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
2419 2962 }
2420 2963 $response=array(
2421 2964 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
... ... @@ -2427,7 +2970,7 @@ class KTWebService
2427 2970 {
2428 2971 $response['message'] = $document->getMessage();
2429 2972 $this->debug("start_document_workflow - cannot get documentid $document_id - " . $document->getMessage(), $session_id);
2430   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2973 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2431 2974 }
2432 2975  
2433 2976 $result = &$document->start_workflow($workflow);
... ... @@ -2435,11 +2978,16 @@ class KTWebService
2435 2978 {
2436 2979 $response['message'] = $result->getMessage();
2437 2980 $this->debug("start_document_workflow - cannot start workflow - " . $result->getMessage(), $session_id);
2438   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2981 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2439 2982 }
2440 2983 $response['status_code'] = KTWS_SUCCESS;
2441 2984  
2442   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  2985 + if ($this->version >= 2)
  2986 + {
  2987 + return $this->get_document_detail($session_id, $document_id);
  2988 + }
  2989 +
  2990 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2443 2991 }
2444 2992  
2445 2993 /**
... ... @@ -2447,15 +2995,20 @@ class KTWebService
2447 2995 *
2448 2996 * @param string $session_id
2449 2997 * @param int $document_id
2450   - * @return kt_response
  2998 + * @return kt_document_detail
2451 2999 */
2452 3000 function delete_document_workflow($session_id,$document_id)
2453 3001 {
2454 3002 $this->debug("delete_document_workflow('$session_id',$document_id)");
2455 3003 $kt = &$this->get_ktapi($session_id );
  3004 + $responseType = 'kt_response';
  3005 + if ($this->version >= 2)
  3006 + {
  3007 + $responseType = 'kt_document_detail';
  3008 + }
2456 3009 if (is_array($kt))
2457 3010 {
2458   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
  3011 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
2459 3012 }
2460 3013 $response=array(
2461 3014 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
... ... @@ -2467,7 +3020,7 @@ class KTWebService
2467 3020 {
2468 3021 $response['message'] = $document->getMessage();
2469 3022 $this->debug("delete_document_workflow - cannot get documentid $document_id - " . $document->getMessage(), $session_id);
2470   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  3023 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2471 3024 }
2472 3025  
2473 3026 $result = $document->delete_workflow();
... ... @@ -2478,8 +3031,12 @@ class KTWebService
2478 3031 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
2479 3032 }
2480 3033 $response['status_code'] = KTWS_SUCCESS;
  3034 + if ($this->version >= 2)
  3035 + {
  3036 + return $this->get_document_detail($session_id, $document_id);
  3037 + }
2481 3038  
2482   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  3039 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2483 3040 }
2484 3041  
2485 3042 /**
... ... @@ -2496,9 +3053,15 @@ class KTWebService
2496 3053 $this->debug("perform_document_workflow_transition('$session_id',$document_id,'$transition','$reason')");
2497 3054  
2498 3055 $kt = &$this->get_ktapi($session_id );
  3056 + $responseType = 'kt_response';
  3057 + if ($this->version >= 2)
  3058 + {
  3059 + $responseType = 'kt_document_detail';
  3060 + }
  3061 +
2499 3062 if (is_array($kt))
2500 3063 {
2501   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
  3064 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
2502 3065 }
2503 3066 $response=array(
2504 3067 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
... ... @@ -2510,7 +3073,7 @@ class KTWebService
2510 3073 {
2511 3074 $response['message'] = $document->getMessage();
2512 3075 $this->debug("perform_document_workflow_transition - cannot get document - " . $document->getMessage(), $session_id);
2513   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  3076 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2514 3077 }
2515 3078  
2516 3079 $result = $document->perform_workflow_transition($transition,$reason);
... ... @@ -2518,11 +3081,16 @@ class KTWebService
2518 3081 {
2519 3082 $response['message'] = $result->getMessage();
2520 3083 $this->debug("perform_document_workflow_transition - cannot perform transition - " . $result->getMessage(), $session_id);
2521   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  3084 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2522 3085 }
2523 3086 $response['status_code'] = KTWS_SUCCESS;
2524 3087  
2525   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  3088 + if ($this->version >= 2)
  3089 + {
  3090 + return $this->get_document_detail($session_id, $document_id);
  3091 + }
  3092 +
  3093 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2526 3094 }
2527 3095  
2528 3096 /**
... ... @@ -2814,16 +3382,22 @@ class KTWebService
2814 3382 * @param string $session_id
2815 3383 * @param int $document_id
2816 3384 * @param array $metadata
2817   - * @return kt_response
  3385 + * @return kt_document_detail
2818 3386 */
2819   - function update_document_metadata($session_id,$document_id,$metadata)
  3387 + function update_document_metadata($session_id,$document_id,$metadata, $sysdata=null)
2820 3388 {
2821   - $this->debug("update_document_metadata('$session_id',$document_id,$metadata)");
  3389 + $this->debug("update_document_metadata('$session_id',$document_id,$metadata, $sysdata)");
2822 3390  
2823 3391 $kt = &$this->get_ktapi($session_id );
  3392 + $responseType = 'kt_response';
  3393 + if ($this->version >= 2)
  3394 + {
  3395 + $responseType = 'kt_document_detail';
  3396 + }
  3397 +
2824 3398 if (is_array($kt))
2825 3399 {
2826   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
  3400 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
2827 3401 }
2828 3402 $response=array(
2829 3403 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
... ... @@ -2835,7 +3409,7 @@ class KTWebService
2835 3409 {
2836 3410 $response['message'] = $document->getMessage();
2837 3411 $this->debug("update_document_metadata - cannot get documentid $document_id - " . $document->getMessage(), $session_id);
2838   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  3412 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2839 3413 }
2840 3414  
2841 3415 $result = $document->update_metadata($metadata);
... ... @@ -2843,12 +3417,26 @@ class KTWebService
2843 3417 {
2844 3418 $response['message'] = $result->getMessage();
2845 3419 $this->debug("update_document_metadata - cannot update metadata - " . $result->getMessage(), $session_id);
2846   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  3420 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2847 3421 }
2848 3422  
  3423 +
  3424 + if ($this->version >= 2)
  3425 + {
  3426 + $result = $document->update_sysdata($sysdata);
  3427 + if (PEAR::isError($result))
  3428 + {
  3429 + $response['message'] = $result->getMessage();
  3430 + $this->debug("update_document_metadata - cannot update sysdata - " . $result->getMessage(), $session_id);
  3431 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
  3432 + }
  3433 +
  3434 +
  3435 + return $this->get_document_detail($session_id, $document_id, 'M');
  3436 + }
2849 3437 $response['status_code'] = KTWS_SUCCESS;
2850 3438  
2851   - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  3439 + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2852 3440  
2853 3441 }
2854 3442  
... ... @@ -3149,7 +3737,7 @@ class KTWebService
3149 3737 $response=array(
3150 3738 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
3151 3739 'message'=>'',
3152   - 'parent_document_id' => $document_id,
  3740 + 'parent_document_id' => (int) $document_id,
3153 3741 'links'=>array()
3154 3742 );
3155 3743  
... ... @@ -3162,7 +3750,8 @@ class KTWebService
3162 3750 }
3163 3751  
3164 3752 $links = $document->get_linked_documents();
3165   - $response['links'] = $links;
  3753 + $response['links'] = new SOAP_Value('links',"{urn:$this->namespace}kt_linked_documents", $links);
  3754 + $response['status_code'] = KTWS_SUCCESS;
3166 3755  
3167 3756 return new SOAP_Value('return',"{urn:$this->namespace}kt_linked_document_response", $response);
3168 3757 }
... ... @@ -3364,65 +3953,34 @@ class KTWebService
3364 3953 return new SOAP_Value('return',"{urn:$this->namespace}kt_search_response", $kt);
3365 3954 }
3366 3955 $response=array(
3367   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
  3956 + 'status_code'=>KTWS_ERR_PROBLEM,
3368 3957 'message'=>'',
3369 3958 'hits'=>array()
3370 3959 );
3371 3960  
3372   - $noText = (stripos($options,'notext') !== false);
3373   - $results = array();
3374   -
3375   - try
  3961 + if (!defined('HAS_SEARCH_FUNCTIONALITY'))
3376 3962 {
3377   - $expr = parseExpression($query);
3378   -
3379   - $rs = $expr->evaluate();
3380   - usort($rs, 'rank_compare');
3381   -
3382   - $results = array();
3383   - foreach($rs as $hit)
3384   - {
3385   - $item = array(
3386   - 'document_id' => (int) $hit->DocumentID,
3387   - 'title' => (string) $hit->Title,
3388   - 'relevance' => (float) $hit->Rank,
3389   - 'text' => (string) $noText?'':$hit->Text,
3390   - 'filesize' => (int) $hit->Filesize,
3391   - 'fullpath' => (string) $hit->FullPath,
3392   - 'version' => (string) $hit->Version,
3393   - 'filename' => (string) $hit->Filename,
3394   - 'checked_out_by' => (string) $hit->CheckedOutUser,
3395   - 'checked_out_date' => (string) $hit->DateCheckedOut,
3396   - 'is_available' => (bool) $hit->IsAvailable,
3397   - 'workflow' => (string) $hit->Workflow,
3398   - 'workflow_state' => (string) $hit->WorkflowState,
3399   - 'folder_id' => (int) $hit->FolderId,
3400   - 'mime_type' => (string) $hit->MimeType,
3401   - 'modified_by' => (string) $hit->ModifiedBy,
3402   - 'modified_date' => (string) $hit->DateModified,
3403   - 'created_by' => (string) $hit->CreatedBy,
3404   - 'created_date' => (string) $hit->DateCreated,
3405   - 'owner' => (string) $hit->Owner,
3406   - 'is_immutable'=> (bool) $hit->Immutable,
3407   - 'status' => (string) $hit->Status
3408   - );
3409   -
3410   - $item = new SOAP_Value('item',"{urn:$this->namespace}kt_search_result_item", $item);
3411   - $results[] = $item;
3412   -
3413   - }
  3963 + $response['message'] = _kt('Search has not been implemented for this version of KnowledgeTree');
  3964 + return new SOAP_Value('return',"{urn:$this->namespace}kt_search_response", $response);
  3965 + }
3414 3966  
3415   - $response['message'] = '';
  3967 + $results = processSearchExpression($query);
  3968 + if (PEAR::isError($results))
  3969 + {
  3970 + $response['message'] = _kt('Could not process query.') . $results->getMessage();
  3971 + $results = array();
  3972 + }
  3973 + else
  3974 + {
  3975 + foreach($results as $key=>$item)
  3976 + {
  3977 + $results[$key] = new SOAP_Value('item',"{urn:$this->namespace}kt_search_result_item", $item);
  3978 + }
  3979 + $response['message'] = '';
3416 3980 $response['status_code'] = KTWS_SUCCESS;
3417   - }
3418   - catch(Exception $e)
3419   - {
3420   - $this->debug("search - exception " . $e->getMessage(), $session_id);
3421 3981  
3422   - $results = array();
3423   - $response['message'] = _kt('Could not process query.') . $e->getMessage();
3424   - }
3425   - $response['hits'] = new SOAP_Value('hits',"{urn:$this->namespace}kt_search_results", $results);
  3982 + }
  3983 + $response['hits'] = new SOAP_Value('hits',"{urn:$this->namespace}kt_search_results", $results);
3426 3984  
3427 3985 return new SOAP_Value('return',"{urn:$this->namespace}kt_search_response", $response);
3428 3986 }
... ... @@ -3435,13 +3993,17 @@ class KTWebService
3435 3993 */
3436 3994 function run()
3437 3995 {
  3996 + ob_start();
3438 3997 $server = new SOAP_Server();
3439 3998  
3440 3999 $server->addObjectMap($this, 'http://schemas.xmlsoap.org/soap/envelope/');
  4000 + $request = 'Not Set';
3441 4001  
3442 4002 if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD']=='POST')
3443 4003 {
3444   - $server->service(file_get_contents("php://input"));
  4004 + $request = file_get_contents("php://input");
  4005 +
  4006 + $server->service($request);
3445 4007 }
3446 4008 else
3447 4009 {
... ... @@ -3457,6 +4019,12 @@ class KTWebService
3457 4019 echo $disco->getDISCO();
3458 4020 }
3459 4021 }
  4022 + $capture = ob_get_flush();
  4023 + $this->debug($request,'request', 5);
  4024 + $this->debug($capture,'response',5);
  4025 + global $_KT_starttime;
  4026 + $time = number_format(KTUtil::getBenchmarkTime() - $_KT_starttime,2);
  4027 + $this->debug($time, 'time from start',4);
3460 4028 }
3461 4029  
3462 4030 function __dispatch($methodname)
... ... @@ -3470,6 +4038,7 @@ class KTWebService
3470 4038  
3471 4039 }
3472 4040  
  4041 +
3473 4042 $webservice = new KTWebService();
3474 4043 $webservice->run();
3475 4044  
... ...
lib/browse/browseutil.inc.php
... ... @@ -7,32 +7,32 @@
7 7 * KnowledgeTree Open Source Edition
8 8 * Document Management Made Simple
9 9 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
10   - *
  10 + *
11 11 * This program is free software; you can redistribute it and/or modify it under
12 12 * the terms of the GNU General Public License version 3 as published by the
13 13 * Free Software Foundation.
14   - *
  14 + *
15 15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 18 * details.
19   - *
  19 + *
20 20 * You should have received a copy of the GNU General Public License
21 21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22   - *
  22 + *
23 23 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
24 24 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
25   - *
  25 + *
26 26 * The interactive user interfaces in modified source and object code versions
27 27 * of this program must display Appropriate Legal Notices, as required under
28 28 * Section 5 of the GNU General Public License version 3.
29   - *
  29 + *
30 30 * In accordance with Section 7(b) of the GNU General Public License version 3,
31 31 * these Appropriate Legal Notices must retain the display of the "Powered by
32   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
33 33 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
34   - * must display the words "Powered by KnowledgeTree" and retain the original
35   - * copyright notice.
  34 + * must display the words "Powered by KnowledgeTree" and retain the original
  35 + * copyright notice.
36 36 * Contributor( s): ______________________________________
37 37 */
38 38  
... ... @@ -381,20 +381,26 @@ class KTBrowseUtil {
381 381 }
382 382 $sPermissionDescriptors = DBUtil::paramArray($aPermissionDescriptors);
383 383  
  384 + $oPermission = KTPermission::getByName('ktcore.permissions.read');
  385 + $oPermission2 = KTPermission::getByName('ktcore.permissions.folder_details');
  386 + $aPermissionIds = array($oPermission->getId(), $oPermission->getId(), $oPermission2->getId(), $oPermission2->getId());
  387 +
384 388 $sFoldersTable = KTUtil::getTableName('folders');
385 389 $sPLTable = KTUtil::getTableName('permission_lookups');
386 390 $sPLATable = KTUtil::getTableName('permission_lookup_assignments');
387   - $oPermission = KTPermission::getByName('ktcore.permissions.read');
388 391 $sQuery = "SELECT DISTINCT F.id AS id FROM
389 392 $sFoldersTable AS F
390   - LEFT JOIN $sPLTable AS PL ON F.permission_lookup_id = PL.id LEFT JOIN $sPLATable AS PLA ON PLA.permission_lookup_id = PL.id AND PLA.permission_id = ?
  393 + LEFT JOIN $sPLTable AS PL ON F.permission_lookup_id = PL.id
  394 + LEFT JOIN $sPLATable AS PLA ON PLA.permission_lookup_id = PL.id AND (PLA.permission_id = ? || PLA.permission_id = ?)
  395 +
391 396 LEFT JOIN $sFoldersTable AS F2 ON F.parent_id = F2.id
392   - LEFT JOIN $sPLTable AS PL2 ON F2.permission_lookup_id = PL2.id LEFT JOIN $sPLATable AS PLA2 ON PLA2.permission_lookup_id = PL2.id AND PLA2.permission_id = ?
  397 + LEFT JOIN $sPLTable AS PL2 ON F2.permission_lookup_id = PL2.id
  398 + LEFT JOIN $sPLATable AS PLA2 ON PLA2.permission_lookup_id = PL2.id AND (PLA2.permission_id = ? || PLA.permission_id = ?)
393 399 WHERE
394 400 PLA.permission_descriptor_id IN ($sPermissionDescriptors)
395 401 AND F2.id <> 1
396 402 AND NOT (PLA2.permission_descriptor_id IN ($sPermissionDescriptors))";
397   - $aParams = kt_array_merge(array($oPermission->getId(), $oPermission->getId()), $aPermissionDescriptors, $aPermissionDescriptors);
  403 + $aParams = kt_array_merge($aPermissionIds, $aPermissionDescriptors, $aPermissionDescriptors);
398 404 $res = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id');
399 405  
400 406 if (PEAR::isError($res)) {
... ...
lib/documentmanagement/documentutil.inc.php
... ... @@ -638,14 +638,14 @@ class KTDocumentUtil {
638 638 return $oDocument;
639 639 }
640 640 // }}}
641   -
  641 +
642 642 function generateNewDocumentFilename($sDocFilename){
643 643 if(preg_match("/\([0-9]+\)(\.[^\.]+){1,}$/", $sDocFilename)){
644 644 preg_match("/\([0-9]+\)\./", $sDocFilename, $matches);
645 645 $new_one = substr($matches[0], 1);
646 646 $new_two = explode(')', $new_one);
647 647 $new = $new_two[0]+1;
648   -
  648 +
649 649 $pattern[0] = '/\([0-9]+\)\./';
650 650 $replacement[0] = ' ('.$new.').';
651 651 $sFilename = preg_replace($pattern, $replacement, $sDocFilename);
... ... @@ -657,27 +657,27 @@ class KTDocumentUtil {
657 657 }
658 658 $sFilename = $prefix.$suffix;
659 659 }
660   -
  660 +
661 661 return $sFilename;
662 662 }
663   -
664   - function generateNewDocumentName($sDocName){
  663 +
  664 + function generateNewDocumentName($sDocName){
665 665 if(preg_match("/\([0-9]+\)$/", $sDocName)){
666 666 preg_match("/\([0-9]+\)$/", $sDocName, $matches);
667 667 $new_one = substr($matches[0], 1);
668 668 $new_two = explode(')', $new_one);
669 669 $new = $new_two[0]+1;
670   -
  670 +
671 671 $pattern[0] = '/\([0-9]+\)$/';
672 672 $replacement[0] = '('.$new.')';
673 673 $sName = preg_replace($pattern, $replacement, $sDocName);
674 674 }else{
675 675 $sName = $sDocName.' (2)';
676 676 }
677   -
  677 +
678 678 return $sName;
679 679 }
680   -
  680 +
681 681 // {{{ fileExists
682 682 function fileExists($oFolder, $sFilename) {
683 683 return Document::fileExists($sFilename, $oFolder->getID());
... ... @@ -939,7 +939,7 @@ class KTDocumentUtil {
939 939 }
940 940  
941 941  
942   - function copy($oDocument, $oDestinationFolder, $sReason = null) {
  942 + function copy($oDocument, $oDestinationFolder, $sReason = null, $sDestinationDocName = null) {
943 943 // 1. generate a new triad of content, metadata and core objects.
944 944 // 2. update the storage path.
945 945 //print '--------------------------------- BEFORE';
... ... @@ -958,23 +958,36 @@ class KTDocumentUtil {
958 958 // we still have a bogus md_version, but integrity holds, so fix it now.
959 959 $oCore = KTDocumentCore::get($id);
960 960  
  961 + // Get the metadata version for the source document
961 962 $sTable = KTUtil::getTableName('document_metadata_version');
962 963 $sQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ?';
963 964 $aParams = array($oDocument->getMetadataVersionId());
964 965 $aMDRow = DBUtil::getOneResult(array($sQuery, $aParams));
965 966 unset($aMDRow['id']);
  967 +
  968 + // Copy the source metadata into the destination document
966 969 $aMDRow['document_id'] = $oCore->getId();
  970 + if(!empty($sDestinationDocName)){
  971 + $aMDRow['name'] = $sDestinationDocName;
  972 + $aMDRow['description'] = $sDestinationDocName;
  973 + }
967 974 $id = DBUtil::autoInsert($sTable, $aMDRow);
968 975 if (PEAR::isError($id)) { return $id; }
969 976 $oCore->setMetadataVersionId($id);
970 977 $oMDV = KTDocumentMetadataVersion::get($id);
971 978  
  979 + // Get the content version for the source document
972 980 $sTable = KTUtil::getTableName('document_content_version');
973 981 $sQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ?';
974 982 $aParams = array($oDocument->_oDocumentContentVersion->getId());
975 983 $aContentRow = DBUtil::getOneResult(array($sQuery, $aParams));
976 984 unset($aContentRow['id']);
  985 +
  986 + // Copy the source content into the destination document
977 987 $aContentRow['document_id'] = $oCore->getId();
  988 + if(!empty($sDestinationDocName)){
  989 + $aContentRow['filename'] = $sDestinationDocName;
  990 + }
978 991 $id = DBUtil::autoInsert($sTable, $aContentRow);
979 992 if (PEAR::isError($id)) { return $id; }
980 993 $oMDV->setContentVersionId($id);
... ... @@ -996,6 +1009,7 @@ class KTDocumentUtil {
996 1009 $res = KTDocumentUtil::copyMetadata($oNewDocument, $oDocument->getMetadataVersionId());
997 1010 if (PEAR::isError($res)) { return $res; }
998 1011  
  1012 + // Ensure the copied document is not checked out
999 1013 $oNewDocument->setIsCheckedOut(false);
1000 1014 $oNewDocument->setCheckedOutUserID(-1);
1001 1015  
... ...
lib/foldermanagement/folderutil.inc.php
... ... @@ -7,32 +7,32 @@
7 7 * KnowledgeTree Open Source Edition
8 8 * Document Management Made Simple
9 9 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
10   - *
  10 + *
11 11 * This program is free software; you can redistribute it and/or modify it under
12 12 * the terms of the GNU General Public License version 3 as published by the
13 13 * Free Software Foundation.
14   - *
  14 + *
15 15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 18 * details.
19   - *
  19 + *
20 20 * You should have received a copy of the GNU General Public License
21 21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22   - *
  22 + *
23 23 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
24 24 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
25   - *
  25 + *
26 26 * The interactive user interfaces in modified source and object code versions
27 27 * of this program must display Appropriate Legal Notices, as required under
28 28 * Section 5 of the GNU General Public License version 3.
29   - *
  29 + *
30 30 * In accordance with Section 7(b) of the GNU General Public License version 3,
31 31 * these Appropriate Legal Notices must retain the display of the "Powered by
32   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
33 33 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
34   - * must display the words "Powered by KnowledgeTree" and retain the original
35   - * copyright notice.
  34 + * must display the words "Powered by KnowledgeTree" and retain the original
  35 + * copyright notice.
36 36 * Contributor( s): ______________________________________
37 37 */
38 38  
... ... @@ -414,8 +414,9 @@ class KTFolderUtil {
414 414 return true;
415 415 }
416 416  
417   - function copy($oSrcFolder, $oDestFolder, $oUser, $sReason) {
418   - if (KTFolderUtil::exists($oDestFolder, $oSrcFolder->getName())) {
  417 + function copy($oSrcFolder, $oDestFolder, $oUser, $sReason, $sDestFolderName = NULL, $copyAll = true) {
  418 + $sDestFolderName = (empty($sDestFolderName)) ? $oSrcFolder->getName() : $sDestFolderName;
  419 + if (KTFolderUtil::exists($oDestFolder, $sDestFolderName)) {
419 420 return PEAR::raiseError(_kt("Folder with the same name already exists in the new parent folder"));
420 421 }
421 422 //
... ... @@ -437,7 +438,7 @@ class KTFolderUtil {
437 438  
438 439 DBUtil::startTransaction();
439 440  
440   - while (!empty($aRemainingFolders)) {
  441 + while (!empty($aRemainingFolders) && $copyAll) {
441 442 $iFolderId = array_pop($aRemainingFolders);
442 443 $oFolder = Folder::get($iFolderId);
443 444 if (PEAR::isError($oFolder) || ($oFolder == false)) {
... ... @@ -487,15 +488,18 @@ class KTFolderUtil {
487 488  
488 489 $aFolderMap = array();
489 490  
490   - $sTable = KTUtil::getTableName('folders');
  491 + $sTable = 'folders';
491 492 $sGetQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ? ';
492 493 $aParams = array($oSrcFolder->getId());
493 494 $aRow = DBUtil::getOneResult(array($sGetQuery, $aParams));
494 495 unset($aRow['id']);
  496 +
  497 + $aRow['name'] = $sDestFolderName;
  498 + $aRow['description'] = $sDestFolderName;
495 499 $aRow['parent_id'] = $oDestFolder->getId();
496 500 $aRow['parent_folder_ids'] = sprintf('%s,%s', $oDestFolder->getParentFolderIDs(), $oDestFolder->getId());
497 501 $aRow['full_path'] = sprintf('%s/%s', $oDestFolder->getFullPath(), $oDestFolder->getName());
498   -
  502 +
499 503 $id = DBUtil::autoInsert($sTable, $aRow);
500 504 if (PEAR::isError($id)) {
501 505 DBUtil::rollback();
... ... @@ -506,7 +510,7 @@ class KTFolderUtil {
506 510 $aFolderMap[$sSrcFolderId]['parent_folder_ids'] = $aRow['parent_folder_ids'];
507 511 $aFolderMap[$sSrcFolderId]['full_path'] = $aRow['full_path'];
508 512 $aFolderMap[$sSrcFolderId]['name'] = $aRow['name'];
509   -
  513 +
510 514 $oNewBaseFolder = Folder::get($id);
511 515 $res = $oStorage->createFolder($oNewBaseFolder);
512 516 if (PEAR::isError($res)) {
... ... @@ -517,12 +521,13 @@ class KTFolderUtil {
517 521 $aRemainingFolders = Folder::getList(array('parent_id = ?', array($oSrcFolder->getId())), array('ids' => true));
518 522  
519 523  
520   - while (!empty($aRemainingFolders)) {
  524 + while (!empty($aRemainingFolders) && $copyAll) {
521 525 $iFolderId = array_pop($aRemainingFolders);
522 526  
523 527 $aParams = array($iFolderId);
524 528 $aRow = DBUtil::getOneResult(array($sGetQuery, $aParams));
525 529 unset($aRow['id']);
  530 +
526 531 // since we are nested, we will have solved the parent first.
527 532 $sPrevParentId = $aRow['parent_id'];
528 533 $aRow['parent_id'] = $aFolderMap[$aRow['parent_id']]['parent_id'];
... ... @@ -552,7 +557,7 @@ class KTFolderUtil {
552 557 $aCFIds = Folder::getList(array('parent_id = ?', array($iFolderId)), array('ids' => true));
553 558 $aRemainingFolders = kt_array_merge($aRemainingFolders, $aCFIds);
554 559 }
555   -
  560 +
556 561 // now we can go ahead.
557 562 foreach ($aDocuments as $oDocument) {
558 563 $oChildDestinationFolder = Folder::get($aFolderMap[$oDocument->getFolderID()]['parent_id']);
... ...
lib/permissions/permissionutil.inc.php
... ... @@ -5,32 +5,32 @@
5 5 * KnowledgeTree Open Source Edition
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
8   - *
  8 + *
9 9 * This program is free software; you can redistribute it and/or modify it under
10 10 * the terms of the GNU General Public License version 3 as published by the
11 11 * Free Software Foundation.
12   - *
  12 + *
13 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 16 * details.
17   - *
  17 + *
18 18 * You should have received a copy of the GNU General Public License
19 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20   - *
  20 + *
21 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23   - *
  23 + *
24 24 * The interactive user interfaces in modified source and object code versions
25 25 * of this program must display Appropriate Legal Notices, as required under
26 26 * Section 5 of the GNU General Public License version 3.
27   - *
  27 + *
28 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 29 * these Appropriate Legal Notices must retain the display of the "Powered by
30   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  30 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
31 31 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
32   - * must display the words "Powered by KnowledgeTree" and retain the original
33   - * copyright notice.
  32 + * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * copyright notice.
34 34 * Contributor( s): ______________________________________
35 35 *
36 36 */
... ... @@ -52,6 +52,9 @@ require_once(KT_LIB_DIR . &quot;/workflow/workflowutil.inc.php&quot;);
52 52 require_once(KT_LIB_DIR . "/workflow/workflowstatepermissionsassignment.inc.php");
53 53  
54 54 class KTPermissionUtil {
  55 +
  56 + static $permArr = array();
  57 +
55 58 // {{{ generateDescriptor
56 59 /**
57 60 * Generate a unique textual representation of a specific collection
... ... @@ -93,7 +96,7 @@ class KTPermissionUtil {
93 96 $oDescriptor =& KTPermissionDescriptor::getByDescriptor(md5($sDescriptor));
94 97 if (PEAR::isError($oDescriptor)) {
95 98 $oOriginalDescriptor = $oDescriptor;
96   -
  99 +
97 100 $oDescriptor =& KTPermissionDescriptor::createFromArray(array(
98 101 "descriptortext" => $sDescriptor,
99 102 ));
... ... @@ -112,7 +115,7 @@ class KTPermissionUtil {
112 115 exit(0);
113 116 }
114 117 $oDescriptor->saveAllowed($aAllowed);
115   -
  118 +
116 119 }
117 120 return $oDescriptor;
118 121 }
... ... @@ -193,7 +196,7 @@ class KTPermissionUtil {
193 196 $sWhere = 'permission_object_id = ?';
194 197 $aParams = array($oPO->getID());
195 198 $aFolders =& Folder::getList(array($sWhere, $aParams));
196   - if (!PEAR::isError($aFolders)) {
  199 + if (!PEAR::isError($aFolders)) {
197 200 foreach ($aFolders as $oFolder) {
198 201 KTPermissionUtil::updatePermissionLookup($oFolder);
199 202 }
... ... @@ -253,7 +256,7 @@ class KTPermissionUtil {
253 256 }
254 257 }
255 258 }
256   -
  259 +
257 260 $oChannel =& KTPermissionChannel::getSingleton();
258 261 if (is_a($oFolderOrDocument, 'Folder')) {
259 262 $msg = sprintf("Updating folder %s", join("/", $oFolderOrDocument->getPathArray()));
... ... @@ -265,7 +268,7 @@ class KTPermissionUtil {
265 268 }
266 269 }
267 270 $oChannel->sendMessage(new KTPermissionGenericMessage($msg));
268   - //var_dump($msg);
  271 + //var_dump($msg);
269 272 $iPermissionObjectId = $oFolderOrDocument->getPermissionObjectID();
270 273 if (empty($iPermissionObjectId)) {
271 274 return;
... ... @@ -311,7 +314,7 @@ class KTPermissionUtil {
311 314 foreach ($aWorkflowStatePermissionAssignments as $oAssignment) {
312 315 $iPermissionId = $oAssignment->getPermissionId();
313 316 $iPermissionDescriptorId = $oAssignment->getDescriptorId();
314   -
  317 +
315 318 $oPD = KTPermissionDescriptor::get($iPermissionDescriptorId);
316 319 $aGroupIDs = $oPD->getGroups();
317 320 $aUserIDs = array();
... ... @@ -330,16 +333,16 @@ class KTPermissionUtil {
330 333 $iRoleSourceFolder = null;
331 334 if (is_a($oFolderOrDocument, 'KTDocumentCore') || is_a($oFolderOrDocument, 'Document')) { $iRoleSourceFolder = $oFolderOrDocument->getFolderID(); }
332 335 else { $iRoleSourceFolder = $oFolderOrDocument->getId(); }
333   -
  336 +
334 337 // very minor perf win: map role_id (in context) to PD.
335   - $_roleCache = array();
336   -
  338 + $_roleCache = array();
  339 +
337 340 foreach ($aMapPermAllowed as $iPermissionId => $aAllowed) {
338 341 $aAfterRoles = array();
339 342 if (array_key_exists('role', $aAllowed)) {
340 343 foreach ($aAllowed['role'] as $k => $iRoleId) {
341 344 // store the PD <-> RoleId map
342   -
  345 +
343 346 // special-case "all" or "authenticated".
344 347 if (($iRoleId == -3) || ($iRoleId == -4)) {
345 348 $aAfterRoles[] = $iRoleId;
... ... @@ -366,15 +369,15 @@ class KTPermissionUtil {
366 369  
367 370 unset($aAllowed['role'][$k]);
368 371 }
369   -
  372 +
370 373 }
371 374  
372   - unset($aMapPermAllowed[$iPermissionId]['role']);
373   - if (!empty($aAfterRoles)) {
  375 + unset($aMapPermAllowed[$iPermissionId]['role']);
  376 + if (!empty($aAfterRoles)) {
374 377 $aMapPermAllowed[$iPermissionId]['role'] = $aAfterRoles;
375 378 }
376 379 }
377   -
  380 +
378 381 /*
379 382 print '<pre>';
380 383 print '=======' . $oFolderOrDocument->getName();
... ... @@ -382,7 +385,7 @@ class KTPermissionUtil {
382 385 var_dump($aMapPermAllowed);
383 386 print '</pre>';
384 387 */
385   -
  388 +
386 389  
387 390 $aMapPermDesc = array();
388 391 foreach ($aMapPermAllowed as $iPermissionId => $aAllowed) {
... ... @@ -404,6 +407,7 @@ class KTPermissionUtil {
404 407 * and so forth.
405 408 */
406 409 function userHasPermissionOnItem($oUser, $oPermission, $oFolderOrDocument) {
  410 +
407 411 if (is_string($oPermission)) {
408 412 $oPermission =& KTPermission::getByName($oPermission);
409 413 }
... ... @@ -413,20 +417,44 @@ class KTPermissionUtil {
413 417 if (PEAR::isError($oFolderOrDocument) || $oFolderOrDocument == null) {
414 418 return false;
415 419 }
  420 +
  421 + // Quick fix for multiple permissions look ups.
  422 + // For the current lookup, if the permissions have been checked then return their value
  423 + $iPermId = $oPermission->getID();
  424 + $iDocId = $oFolderOrDocument->getID();
  425 + $lookup = 'folders';
  426 + if(is_a($oEntity, 'Document') || is_a($oEntity, 'DocumentProxy')){
  427 + $lookup = 'docs';
  428 + }
  429 + // check if permission has been set
  430 + // $permArr[permId] = array('folders' => array('id' => bool), 'docs' => array('id' => bool));
  431 + if(isset($permArr[$iPermId][$lookup][$iDocId])){
  432 + return $permArr[$iPermId][$lookup][$iDocId];
  433 + }
  434 +
  435 +
  436 +
416 437 $oPL = KTPermissionLookup::get($oFolderOrDocument->getPermissionLookupID());
417 438 $oPLA = KTPermissionLookupAssignment::getByPermissionAndLookup($oPermission, $oPL);
418 439 if (PEAR::isError($oPLA)) {
419 440 //print $oPL->getID();
  441 + $permArr[$iPermId][$lookup][$iDocId] = false;
420 442 return false;
421 443 }
422 444 $oPD = KTPermissionDescriptor::get($oPLA->getPermissionDescriptorID());
423   -
  445 +
  446 + // set permission array to true
  447 + $permArr[$iPermId][$lookup][$iDocId] = true;
  448 +
  449 + // check for permissions
424 450 $aGroups = GroupUtil::listGroupsForUserExpand($oUser);
425 451 if ($oPD->hasRoles(array(-3))) { return true; } // everyone has access.
426 452 else if ($oPD->hasUsers(array($oUser))) { return true; }
427 453 else if ($oPD->hasGroups($aGroups)) { return true; }
428 454 else if ($oPD->hasRoles(array(-4)) && !$oUser->isAnonymous()) { return true; }
429   -
  455 +
  456 + // permission isn't true, set to false
  457 + $permArr[$iPermId][$lookup][$iDocId] = false;
430 458 return false;
431 459 }
432 460 // }}}
... ... @@ -496,7 +524,7 @@ class KTPermissionUtil {
496 524 'groupid' => $oOrigDC->getGroupId(),
497 525 'conditionid' => $oOrigDC->getConditionId(),
498 526 ));
499   -
  527 +
500 528 $oNewDC->saveAssignment($oOrigDC->getAssignment());
501 529 }
502 530  
... ... @@ -582,7 +610,7 @@ class KTPermissionUtil {
582 610 $iNewPOID = $oFolder->getPermissionObjectID();
583 611 $oNewPO =& KTPermissionObject::get($iNewPOID);
584 612  
585   -
  613 +
586 614 $oDocumentOrFolder->setPermissionObjectID($iNewPOID);
587 615 $oDocumentOrFolder->update();
588 616  
... ... @@ -591,7 +619,7 @@ class KTPermissionUtil {
591 619 KTPermissionUtil::updatePermissionLookup($oDocumentOrFolder);
592 620 return;
593 621 }
594   -
  622 +
595 623 $iFolderID = $oDocumentOrFolder->getID();
596 624 $sFolderIDs = Folder::generateFolderIDs($iFolderID);
597 625 $sFolderIDs .= '%';
... ...
lib/session/Session.inc
... ... @@ -196,7 +196,7 @@ class Session {
196 196  
197 197 if ($default->systemVersion != $version) {
198 198 if (KTLOG_CACHE) $default->log->info("Session::verify : Database not upgraded");
199   - return PEAR::raiseError(sprintf(_kt('Incompatible database version (%s, expected version %s) - contact the administrator'), $version, $default->systemVersion));
  199 + return PEAR::raiseError(sprintf(_kt('Database incompatibility error: <br> Please ensure that you have completed the database upgrade procedure. <br> Please <a href=%s>click here</a> to complete.'),'setup/upgrade.php' ));
200 200 }
201 201  
202 202 if (empty($sessionID)) {
... ...
lib/util/ktutil.inc
... ... @@ -175,10 +175,10 @@ class KTUtil {
175 175 }
176 176  
177 177 //this function fudges the strlen. It returns a ? when the character is a multi-byte character.
178   - //str len is therefore measured correctly.
  178 + //str len is therefore measured correctly by counting the ?'s.
179 179 //http://www.phpwact.org/php/i18n/charsets
180 180 function utf8_strlen($string){
181   - return strlen(utf8_decode($str));
  181 + return strlen(utf8_decode($string));
182 182 }
183 183  
184 184 static function &arrayGet($aArray, $sKey, $mDefault = null, $bDefaultIfEmpty = true) {
... ...
lib/workflow/workflowutil.inc.php
... ... @@ -5,32 +5,32 @@
5 5 * KnowledgeTree Open Source Edition
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
8   - *
  8 + *
9 9 * This program is free software; you can redistribute it and/or modify it under
10 10 * the terms of the GNU General Public License version 3 as published by the
11 11 * Free Software Foundation.
12   - *
  12 + *
13 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 16 * details.
17   - *
  17 + *
18 18 * You should have received a copy of the GNU General Public License
19 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20   - *
  20 + *
21 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23   - *
  23 + *
24 24 * The interactive user interfaces in modified source and object code versions
25 25 * of this program must display Appropriate Legal Notices, as required under
26 26 * Section 5 of the GNU General Public License version 3.
27   - *
  27 + *
28 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 29 * these Appropriate Legal Notices must retain the display of the "Powered by
30   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  30 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
31 31 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
32   - * must display the words "Powered by KnowledgeTree" and retain the original
33   - * copyright notice.
  32 + * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * copyright notice.
34 34 * Contributor( s): ______________________________________
35 35 *
36 36 */
... ... @@ -837,7 +837,7 @@ class KTWorkflowUtil {
837 837 if (PEAR::isError($res)) { return $res; }
838 838  
839 839 Document::clearAllCaches();
840   - KTWorkflowTransition::clearAllCaches();
  840 + KTWorkflowTransition::clearCachedGroups();
841 841 }
842 842 }
843 843  
... ...
login.php
... ... @@ -95,14 +95,24 @@ class LoginPageDispatcher extends KTDispatcher {
95 95 #var_dump($oUser);
96 96 #var_dump(PEAR::raiseError());
97 97 }
  98 + $iOldUserID = checkLastSessionUserID();
  99 +
  100 + //if the current person logging in isn't the same person who logged out or timed out
  101 + //then set the redirect to the dashboard and not the last page that was viewed.
  102 + if ($oUser->getId() != $iOldUserID['user_id'])
  103 + {
  104 + $_REQUEST['redirect'] = generateControllerLink('dashboard');
  105 +
  106 + }
  107 +
98 108 $session = new Session();
99 109 $sessionID = $session->create($oUser);
100 110 if (PEAR::isError($sessionID)) {
101 111 return $sessionID;
102 112 }
103   -
104   - $redirect = KTUtil::arrayGet($_REQUEST, 'redirect');
105   -
  113 +
  114 + $redirect = KTUtil::arrayGet($_REQUEST, 'redirect');
  115 +
106 116 // DEPRECATED initialise page-level authorisation array
107 117 $_SESSION["pageAccess"] = NULL;
108 118  
... ... @@ -145,6 +155,10 @@ class LoginPageDispatcher extends KTDispatcher {
145 155 header('Content-type: text/html; charset=UTF-8');
146 156  
147 157 $errorMessage = KTUtil::arrayGet($_REQUEST, 'errorMessage');
  158 + session_start();
  159 +
  160 + $errorMessageConfirm = $_SESSION['errormessage']['login'];
  161 +
148 162 $redirect = KTUtil::arrayGet($_REQUEST, 'redirect');
149 163  
150 164 $oReg =& KTi18nregistry::getSingleton();
... ... @@ -168,6 +182,7 @@ class LoginPageDispatcher extends KTDispatcher {
168 182 $aTemplateData = array(
169 183 "context" => $this,
170 184 'errorMessage' => $errorMessage,
  185 + 'errorMessageConfirm' => $errorMessageConfirm,
171 186 'redirect' => $redirect,
172 187 'systemVersion' => $default->systemVersion,
173 188 'versionName' => $default->versionName,
... ... @@ -322,6 +337,14 @@ class LoginPageDispatcher extends KTDispatcher {
322 337 }
323 338 }
324 339  
  340 +//FIXME Direct Database Access
  341 +//checkLastSessionUserID finds the last user to logout or timeout
  342 +function checkLastSessionUserID()
  343 +{
  344 + $sQuery = 'SELECT user_id FROM user_history ORDER BY id DESC LIMIT 1';
  345 + $res = DBUtil::getOneResult($sQuery);
  346 + return $res;
  347 +}
325 348  
326 349 $dispatcher =& new LoginPageDispatcher();
327 350 $dispatcher->dispatch();
... ...
plugins/housekeeper/HouseKeeperPlugin.php
... ... @@ -53,7 +53,9 @@ class HouseKeeperPlugin extends KTPlugin
53 53 $cacheDir = $config->get('cache/cacheDirectory');
54 54 $logDir = $config->get('urls/logDirectory');
55 55 $docsDir = $config->get('urls/documentRoot');
56   - $luceneDir = $config->get('indexer/luceneDirectory');
  56 +
  57 + $indexer = Indexer::get();
  58 + $luceneDir = $indexer->getIndexDirectory();
57 59  
58 60 $systemDir = OS_UNIX?'/tmp':'c:/windows/temp';
59 61  
... ... @@ -85,6 +87,8 @@ class HouseKeeperPlugin extends KTPlugin
85 87 'canClean'=>true
86 88 );
87 89  
  90 + if (is_dir($docsDir))
  91 + {
88 92 $this->folders[] =
89 93 array(
90 94 'name'=>_kt('KnowledgeTree Documents'),
... ... @@ -92,6 +96,10 @@ class HouseKeeperPlugin extends KTPlugin
92 96 'pattern'=>'',
93 97 'canClean'=>false
94 98 );
  99 + }
  100 +
  101 + if (is_dir($luceneDir))
  102 + {
95 103 $this->folders[] =
96 104 array(
97 105 'name'=>_kt('KnowledgeTree Document Index'),
... ... @@ -99,6 +107,7 @@ class HouseKeeperPlugin extends KTPlugin
99 107 'pattern'=>'',
100 108 'canClean'=>false
101 109 );
  110 + }
102 111  
103 112 }
104 113  
... ...
plugins/ktcore/admin/managePermissions.php
... ... @@ -44,13 +44,25 @@ require_once(KT_LIB_DIR . &quot;/widgets/fieldWidgets.php&quot;);
44 44 class ManagePermissionsDispatcher extends KTAdminDispatcher {
45 45 var $sHelpPage = 'ktcore/admin/manage permissions.html';
46 46 function do_main() {
  47 + session_start();
47 48 $this->oPage->setTitle(_kt('Manage Permissions'));
48 49 $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Manage Permissions'));
49 50  
50 51 $add_fields = array();
51   - $add_fields[] = new KTStringWidget(_kt('System Name'), _kt('The internal name used for the permission. This should never be changed.'), 'name', null, $this->oPage, true);
52   - $add_fields[] = new KTStringWidget(_kt('Display Name'), _kt('A short name that is shown to users whenever permissions must be assigned.'), 'human_name', null, $this->oPage, true);
  52 + $add_fields[] = new KTStringWidget(_kt('System Name'), _kt('The internal name used for the permission. This should never be changed.'), 'name', null, $this->oPage, true, 'name');
  53 + $add_fields[] = new KTStringWidget(_kt('Display Name'), _kt('A short name that is shown to users whenever permissions must be assigned.'), 'human_name', null, $this->oPage, true, 'human_name');
53 54  
  55 + if($_SESSION['Permission']['NameValue'])
  56 + {
  57 + $this->sNameVal = $_SESSION['Permission']['NameValue'];
  58 + $_SESSION['Permission']['NameValue'] = '';
  59 + }
  60 + else if($_SESSION['Permission']['HumanNameValue'])
  61 + {
  62 + $this->sHumanNameVal = $_SESSION['Permission']['HumanNameValue'];
  63 + $_SESSION['Permission']['HumanNameValue'] = '';
  64 + }
  65 +
54 66 $oTemplating =& KTTemplating::getSingleton();
55 67 $aPermissions =& KTPermission::getList();
56 68 $oTemplate = $oTemplating->loadTemplate("ktcore/manage_permissions");
... ... @@ -63,17 +75,75 @@ class ManagePermissionsDispatcher extends KTAdminDispatcher {
63 75 }
64 76  
65 77 function do_newPermission() {
66   - $name = KTUtil::arrayGet($_REQUEST, 'name');
67   - $human_name = KTUtil::arrayGet($_REQUEST, 'human_name');
68   - if (empty($name) || empty($human_name)) {
69   - return $this->errorRedirectToMain(_kt("Both names not given"));
  78 + session_start();
  79 + $sName = KTUtil::arrayGet($_REQUEST, 'name');
  80 + $sHumanName = KTUtil::arrayGet($_REQUEST, 'human_name');
  81 + $sError = 'An error occured while creating your permission';
  82 +
  83 + //Checking that the System Name and Display Name fields aren't empty
  84 + if (empty($sName) && !empty($sHumanName))
  85 + {
  86 + $sError = 'An error occured while creating your permission: The System Name was not provided.';
  87 + $_SESSION['Permission']['HumanNameValue'] = $sHumanName;
  88 + return $this->errorRedirectToMain(_kt($sError));
70 89 }
71   - $oPerm = KTPermission::createFromArray(array(
72   - 'name' => $name,
73   - 'humanname' => $human_name,
  90 + else if(!empty($sName) && empty($sHumanName))
  91 + {
  92 + $sError = 'An error occured while creating your permission: The Display Name was not provided.';
  93 + $_SESSION['Permission']['NameValue'] = $sName;
  94 + return $this->errorRedirectToMain(_kt($sError));
  95 + }
  96 + else if (empty($sName) && empty($sHumanName))
  97 + {
  98 + $sError = 'An error occured while creating your permission: The Display Name and System Name weren\'t provided.';
  99 + return $this->errorRedirectToMain(_kt($sError));
  100 + }
  101 +
  102 + //Checking that the System Name and Display Name aren't already in the database
  103 + $aPermissions = KTPermission::getList();
  104 + //$iNameErrorCount and $iHumanNameErrorCount are used to check whether only one name is duplicated or if two names are duplicated.
  105 + $iNameErrorCount = 0;
  106 + $iHumanNameErrorCount = 0;
  107 + foreach ($aPermissions as $aPermission)
  108 + {
  109 + if($sName == $aPermission->getName())
  110 + {
  111 + $iNameErrorCount ++;
  112 + }
  113 + if ($sHumanName == $aPermission->getHumanName())
  114 + {
  115 + $iHumanNameErrorCount ++;
  116 + }
  117 + }
  118 + if ($iNameErrorCount > 0 && $iHumanNameErrorCount > 0)
  119 + {
  120 + $sError = 'An error occured while creating your permission: The Display Name and System Name you have provided both already exist.';
  121 + return $this->errorRedirectToMain(_kt($sError));
  122 + }
  123 + else if ($iNameErrorCount > 0 && $iHumanNameErrorCount == 0)
  124 + {
  125 + if(!empty($sHumanName))
  126 + {
  127 + $_SESSION['Permission']['HumanNameValue'] = $sHumanName;
  128 + }
  129 + $sError = 'An error occured while creating your permission: A permission with the same System Name already exists.';
  130 + return $this->errorRedirectToMain(_kt($sError));
  131 + }
  132 + else if ($iNameErrorCount == 0 && $iHumanNameErrorCount > 0)
  133 + {
  134 + if(!empty($sName))
  135 + {
  136 + $_SESSION['Permission']['NameValue'] = $sName;
  137 + }
  138 + $sError = 'An error occured while creating your permission: A permission with the same Display Name already exists.';
  139 + return $this->errorRedirectToMain(_kt($sError));
  140 + }
  141 + $oPerm = KTPermission::createFromArray(array(
  142 + 'name' => $sName,
  143 + 'humanname' => $sHumanName,
74 144 ));
75 145 if (PEAR::isError($oPerm)) {
76   - return $this->errorRedirectToMain(_kt("Error creating permission"));
  146 + return $this->errorRedirectToMain(_kt($sError));
77 147 }
78 148 return $this->successRedirectToMain(_kt("Permission created"));
79 149 }
... ...
plugins/rssplugin/loadFeed.inc.php
1 1 <?php
2 2 /*
3   - * $Id:$
  3 + * $Id$
4 4 *
5 5 * KnowledgeTree Open Source Edition
6 6 * Document Management Made Simple
... ... @@ -49,13 +49,19 @@
49 49 // If it is a url, it is an external feed
50 50 $aRSSArray = rss2array($feed);
51 51 }
52   -
  52 + if(count($aRSSArray[errors]) > 0){
  53 + for($i=0;$i<count($aRSSArray[errors]);$i++){
  54 + $response .= $aRSSArray[errors][$i].'<br>';
  55 + echo '<br>'.$response.'<br>';
  56 + return;
  57 + }
  58 + }
53 59 // Prepare response data to be passed back to page
54   - $reposonse = "<h3>".$aRSSArray[channel][title]."</h3>" .
  60 + $response = "<h3>".$aRSSArray[channel][title]."</h3>" .
55 61 "<div class='outerContainer' id='outerContainer'>" .
56 62 "<table width='90%'>";
57 63 for($i=0;$i<count($aRSSArray[items]);$i++){
58   - $reposonse .= "<tr>
  64 + $response .= "<tr>
59 65 <td colspan='2'><strong><a href='".$aRSSArray[items][$i][link]."' target='_blank'>".$aRSSArray[items][$i][title]."</a><strong></td>
60 66 </tr>
61 67 <tr>
... ... @@ -63,7 +69,7 @@
63 69 </tr>
64 70 <tr><td colspan='2'><br></td></tr>";
65 71 }
66   - $reposonse .= "</table></div><br>";
  72 + $response .= "</table></div><br>";
67 73  
68   - echo $reposonse;
  74 + echo $response;
69 75 ?>
... ...
plugins/rssplugin/rss2array.inc.php
1 1 <?php
2 2  
3 3 /*
4   - * $Id:$
  4 + * $Id$
5 5 *
6 6 * KnowledgeTree Open Source Edition
7 7 * Document Management Made Simple
... ... @@ -80,8 +80,8 @@
80 80 #
81 81 # open the connection
82 82 #
83   -
84   - if($http = fsockopen($host, $port, $errno, $errstr, 5)){
  83 + $http = @fsockopen($host, $port, $errno, $errstr, 5);
  84 + if($http){
85 85  
86 86 #
87 87 # make the request
... ... @@ -169,7 +169,6 @@
169 169 #
170 170  
171 171 else {
172   -
173 172 $rss2array_globals[errors][] = "Can't connect to $host";
174 173  
175 174 }
... ...
plugins/search2/ExternalDashlet.php
... ... @@ -104,7 +104,7 @@ class ExternalResourceStatusDashlet extends KTBaseDashlet
104 104  
105 105 function checkDF()
106 106 {
107   - $df = KTUtil::findCommand('externalBinary','df');
  107 + $df = KTUtil::findCommand('externalBinary/df','df');
108 108  
109 109 if (false === $df)
110 110 {
... ...
resources/graphics/download.png

586 Bytes | W: | H:

523 Bytes | W: | H:

  • 2-up
  • Swipe
  • Onion skin
search2/indexing/bin/optimise.php
... ... @@ -46,11 +46,15 @@ chdir(dirname(__FILE__));
46 46 require_once(realpath('../../../config/dmsDefaults.php'));
47 47 require_once('indexing/indexerCore.inc.php');
48 48  
49   -print _kt("Optimising Lucene index") . "...\n";
  49 +$verbose = false;
  50 +
  51 +if (is_array($argv) && in_array('verbose', $argv)) $verbose = true;
  52 +
  53 +if ($verbose) print _kt("Optimising Lucene index") . "...\n";
50 54  
51 55 $indexer = Indexer::get();
52 56 $indexer->optimise();
53 57  
54   -print _kt("Done.") . "\n";
  58 +if ($verbose) print _kt("Done.") . "\n";
55 59  
56 60 ?>
57 61 \ No newline at end of file
... ...
search2/indexing/indexerCore.inc.php
... ... @@ -37,7 +37,7 @@
37 37 */
38 38  
39 39 require_once('indexing/extractorCore.inc.php');
40   -
  40 +require_once(KT_DIR . '/plugins/ktcore/scheduler/schedulerUtil.php');
41 41  
42 42 class QueryResultItem
43 43 {
... ... @@ -306,16 +306,14 @@ abstract class Indexer
306 306 */
307 307 protected function __construct()
308 308 {
309   - $this->extractorCache=array();
310   - $this->debug=true;
311   - $this->hookCache = array();
312   - $this->generalHookCache = array();
313   -
314 309 $config = KTConfig::getSingleton();
315 310  
316   - $this->extractorPath = $config->get('indexer/extractorPath', 'extractors');
317   - $this->hookPath = $config->get('indexer/extractorHookPath','extractorHooks');
318   -
  311 + $this->extractorCache = array();
  312 + $this->debug = $config->get('indexer/debug', true);
  313 + $this->hookCache = array();
  314 + $this->generalHookCache = array();
  315 + $this->extractorPath = $config->get('indexer/extractorPath', 'extractors');
  316 + $this->hookPath = $config->get('indexer/extractorHookPath','extractorHooks');
319 317  
320 318 $this->loadExtractorStatus();
321 319 }
... ... @@ -383,7 +381,7 @@ abstract class Indexer
383 381 $sql = "delete from mime_extractors";
384 382 DBUtil::runQuery($sql);
385 383  
386   - $default->log->debug('clearExtractors');
  384 + if ($this->debug) $default->log->debug('clearExtractors');
387 385 }
388 386  
389 387 /**
... ... @@ -453,7 +451,7 @@ abstract class Indexer
453 451 $sql = "INSERT INTO index_files(document_id, user_id, what) VALUES($document_id, $userid, '$what')";
454 452 DBUtil::runQuery($sql);
455 453  
456   -// if ($this->debug) $default->log->debug("index: Queuing indexing of $document_id");
  454 + $default->log->debug("index: Queuing indexing of $document_id");
457 455 }
458 456  
459 457  
... ... @@ -487,7 +485,7 @@ abstract class Indexer
487 485 );';
488 486 DBUtil::runQuery($sql);
489 487  
490   - // if ($this->debug) $default->log->debug("clearoutDeleted: remove documents");
  488 + $default->log->debug("Indexer::clearoutDeleted: removed documents from indexing queue that have been deleted");
491 489 }
492 490  
493 491  
... ... @@ -679,7 +677,7 @@ abstract class Indexer
679 677 {
680 678 return;
681 679 }
682   - $default->log->info('checkForRegisteredTypes: start');
  680 + if ($this->debug) $default->log->debug('checkForRegisteredTypes: start');
683 681  
684 682 $date = date('Y-m-d H:i');
685 683 $sql = "UPDATE scheduler_tasks SET run_time='$date'";
... ... @@ -701,7 +699,7 @@ abstract class Indexer
701 699 $default->log->info("checkForRegisteredTypes: disabled '$extractor'");
702 700 }
703 701  
704   - $default->log->info('checkForRegisteredTypes: done');
  702 + if ($this->debug) $default->log->debug('checkForRegisteredTypes: done');
705 703 KTUtil::setSystemSetting('mimeTypesRegistered', true);
706 704 }
707 705  
... ... @@ -728,10 +726,11 @@ abstract class Indexer
728 726  
729 727 $this->checkForRegisteredTypes();
730 728  
731   - $default->log->info('indexDocuments: start');
  729 + if ($this->debug) $default->log->debug('indexDocuments: start');
732 730 if (!$this->doesDiagnosticsPass())
733 731 {
734 732 //unlink($indexLockFile);
  733 + if ($this->debug) $default->log->debug('indexDocuments: stopping - diagnostics problem. The dashboard will provide more information.');
735 734 return;
736 735 }
737 736  
... ... @@ -764,6 +763,7 @@ abstract class Indexer
764 763 if (PEAR::isError($result))
765 764 {
766 765 //unlink($indexLockFile);
  766 + if ($this->debug) $default->log->debug('indexDocuments: stopping - db error');
767 767 return;
768 768 }
769 769  
... ... @@ -771,6 +771,7 @@ abstract class Indexer
771 771 if (count($result) == 0)
772 772 {
773 773 //unlink($indexLockFile);
  774 + if ($this->debug) $default->log->debug('indexDocuments: stopping - no work to be done');
774 775 return;
775 776 }
776 777  
... ... @@ -804,17 +805,12 @@ abstract class Indexer
804 805  
805 806 if ($this->debug)
806 807 {
807   - $default->log->debug(sprintf(_kt("Indexing docid: %d extension: '%s' mimetype: '%s' extractor: '%s'"), $docId, $extension,$mimeType,$extractorClass));
  808 + if ($this->debug) $default->log->debug(sprintf(_kt("Indexing docid: %d extension: '%s' mimetype: '%s' extractor: '%s'"), $docId, $extension,$mimeType,$extractorClass));
808 809 }
809 810  
810 811 if (empty($extractorClass))
811 812 {
812   - if ($this->debug)
813   - {
814   - $default->log->debug(sprintf(_kt("No extractor for docid: %d"),$docId));
815   - }
816   -
817   - Indexer::unqueueDocument($docId);
  813 + Indexer::unqueueDocument($docId, sprintf(_kt("No extractor for docid: %d"),$docId));
818 814 continue;
819 815 }
820 816  
... ... @@ -867,8 +863,7 @@ abstract class Indexer
867 863  
868 864 if (empty($sourceFile) || !is_file($sourceFile))
869 865 {
870   - $default->log->error(sprintf(_kt("indexDocuments: source file '%s' for document %d does not exist."),$sourceFile,$docId));
871   - Indexer::unqueueDocument($docId);
  866 + Indexer::unqueueDocument($docId,sprintf(_kt("indexDocuments: source file '%s' for document %d does not exist."),$sourceFile,$docId), 'error');
872 867 continue;
873 868 }
874 869  
... ... @@ -896,10 +891,8 @@ abstract class Indexer
896 891 $extractor->setDocument($document);
897 892 $extractor->setIndexingStatus(null);
898 893 $extractor->setExtractionStatus(null);
899   - if ($this->debug)
900   - {
901   - $default->log->debug(sprintf(_kt("Extra Info docid: %d Source File: '%s' Target File: '%s'"),$docId,$sourceFile,$targetFile));
902   - }
  894 +
  895 + if ($this->debug) $default->log->debug(sprintf(_kt("Extra Info docid: %d Source File: '%s' Target File: '%s'"),$docId,$sourceFile,$targetFile));
903 896  
904 897 $this->executeHook($extractor, 'pre_extract');
905 898 $this->executeHook($extractor, 'pre_extract', $mimeType);
... ... @@ -971,22 +964,32 @@ abstract class Indexer
971 964  
972 965 if ($removeFromQueue)
973 966 {
974   - Indexer::unqueueDocument($docId);
  967 + Indexer::unqueueDocument($docId, sprintf(_kt("Done indexing docid: %d"),$docId));
  968 + }
  969 + else
  970 + {
  971 + if ($this->debug) $default->log->debug(sprintf(_kt("Document docid: %d was not removed from the queue as it looks like there was a problem with the extraction process"),$docId));
975 972 }
976   - if ($this->debug)
977   - {
978   - $default->log->debug(sprintf(_kt("Done indexing docid: %d"),$docId));
979   - }
980   -
981 973 }
982   - $default->log->info('indexDocuments: done');
  974 + if ($this->debug) $default->log->debug('indexDocuments: done');
983 975 //unlink($indexLockFile);
984 976 }
985 977  
986 978 public function migrateDocuments($max=null)
987 979 {
  980 + global $default;
  981 +
  982 + $default->log->info(_kt('migrateDocuments: starting'));
  983 +
988 984 if (!$this->doesDiagnosticsPass(true))
989 985 {
  986 + $default->log->info(_kt('migrateDocuments: stopping - diagnostics problem. The dashboard will provide more information.'));
  987 + return;
  988 + }
  989 +
  990 + if (KTUtil::getSystemSetting('migrationComplete') == 'true')
  991 + {
  992 + $default->log->info(_kt('migrateDocuments: stopping - migration is complete.'));
990 993 return;
991 994 }
992 995  
... ... @@ -996,16 +999,13 @@ abstract class Indexer
996 999 $max = $config->get('indexer/batchMigrateDocument',500);
997 1000 }
998 1001  
999   - global $default;
1000   -
1001 1002 $lockFile = $config->get('cache/cacheDirectory') . '/migration.lock';
1002 1003 if (is_file($lockFile))
1003 1004 {
1004   - $default->log->info(_kt('migrateDocuments: migration lockfile detected. exiting.'));
  1005 + $default->log->info(_kt('migrateDocuments: stopping - migration lockfile detected.'));
1005 1006 return;
1006 1007 }
1007 1008 touch($lockFile);
1008   - $default->log->info(_kt('migrateDocuments: starting!'));
1009 1009  
1010 1010 $startTime = KTUtil::getSystemSetting('migrationStarted');
1011 1011 if (is_null($startTime))
... ... @@ -1015,7 +1015,7 @@ abstract class Indexer
1015 1015  
1016 1016 $maxLoops = 5;
1017 1017  
1018   - $max = floor($max / $maxLoops);
  1018 + $max = ceil($max / $maxLoops);
1019 1019  
1020 1020 $start =KTUtil::getBenchmarkTime();
1021 1021 $noDocs = false;
... ... @@ -1033,6 +1033,7 @@ abstract class Indexer
1033 1033 $result = DBUtil::getResultArray($sql);
1034 1034 if (PEAR::isError($result))
1035 1035 {
  1036 + $default->log->info(_kt('migrateDocuments: db error'));
1036 1037 break;
1037 1038 }
1038 1039  
... ... @@ -1053,7 +1054,7 @@ abstract class Indexer
1053 1054 {
1054 1055 $sql = "DELETE FROM document_text WHERE document_id=$docId";
1055 1056 DBUtil::runQuery($sql);
1056   - $default->log->error(sprintf(_kt('migrateDocuments: Could not get document %d\'s document! Removing content!',$docId)));
  1057 + $default->log->error(sprintf(_kt('migrateDocuments: Could not get document %d\'s document! Removing content!'),$docId));
1057 1058 continue;
1058 1059 }
1059 1060  
... ... @@ -1094,13 +1095,14 @@ abstract class Indexer
1094 1095 KTUtil::setSystemSetting('migrationTime', KTUtil::getSystemSetting('migrationTime',0) + $time);
1095 1096 KTUtil::setSystemSetting('migratedDocuments', KTUtil::getSystemSetting('migratedDocuments',0) + $numDocs);
1096 1097  
1097   - $default->log->info(sprintf(_kt('migrateDocuments: done in %d seconds!'), $time));
  1098 + $default->log->info(sprintf(_kt('migrateDocuments: stopping - done in %d seconds!'), $time));
1098 1099 if ($noDocs)
1099 1100 {
1100 1101 $default->log->info(_kt('migrateDocuments: Completed!'));
1101   - KTUtil::setSystemSetting('migrationComplete', true);
  1102 + KTUtil::setSystemSetting('migrationComplete', 'true');
  1103 + schedulerUtil::deleteByName('Index Migration');
  1104 + $default->log->debug(_kt('migrateDocuments: Disabling \'Index Migration\' task by removing scheduler entry.'));
1102 1105 }
1103   -
1104 1106 }
1105 1107  
1106 1108 /**
... ... @@ -1176,7 +1178,7 @@ abstract class Indexer
1176 1178  
1177 1179 if (!$this->isExtractorEnabled($class))
1178 1180 {
1179   - $default->log->info(sprintf(_kt("diagnose: extractor '%s' is disabled."), $class));
  1181 + $default->log->debug(sprintf(_kt("diagnose: extractor '%s' is disabled."), $class));
1180 1182 continue;
1181 1183 }
1182 1184  
... ... @@ -1263,10 +1265,15 @@ abstract class Indexer
1263 1265 *
1264 1266 * @param int $docid
1265 1267 */
1266   - public static function unqueueDocument($docid)
  1268 + public static function unqueueDocument($docid, $reason=false, $level='debug')
1267 1269 {
1268 1270 $sql = "DELETE FROM index_files WHERE document_id=$docid";
1269 1271 DBUtil::runQuery($sql);
  1272 + if ($reason !== false)
  1273 + {
  1274 + global $default;
  1275 + $default->log->$level("Indexer: removing document $docid from the queue - $reason");
  1276 + }
1270 1277 }
1271 1278  
1272 1279 /**
... ... @@ -1343,6 +1350,18 @@ abstract class Indexer
1343 1350 * @return int
1344 1351 */
1345 1352 public abstract function getDocumentsInIndex();
  1353 +
  1354 + /**
  1355 + * Returns the path to the index directory
  1356 + *
  1357 + * @return string
  1358 + */
  1359 + public function getIndexDirectory()
  1360 + {
  1361 + $config = KTConfig::getSingleton();
  1362 + $directory = $config->get('indexer/luceneDirectory');
  1363 + return $directory;
  1364 + }
1346 1365 }
1347 1366  
1348 1367 ?>
1349 1368 \ No newline at end of file
... ...
search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php
... ... @@ -250,5 +250,20 @@ class JavaXMLRPCLuceneIndexer extends Indexer
250 250 return $stats->countDocuments;
251 251 }
252 252  
  253 + /**
  254 + * Returns the path to the index directory
  255 + *
  256 + * @return string
  257 + */
  258 + public function getIndexDirectory()
  259 + {
  260 + $stats = $this->lucene->getStatistics();
  261 + if ($stats === false || !is_object($stats))
  262 + {
  263 + return false;
  264 + }
  265 + return $stats->indexDirectory;
  266 + }
  267 +
253 268 }
254 269 ?>
255 270 \ No newline at end of file
... ...
search2/search/fields/AnyMetadataField.inc.php
... ... @@ -40,7 +40,7 @@ class AnyMetadataField extends DBFieldExpr
40 40 {
41 41 public function __construct()
42 42 {
43   - parent::__construct('id', 'document_fields_link', _kt('Any Metadata'));
  43 + parent::__construct('value', 'document_fields_link', _kt('Any Metadata'));
44 44 $this->setAlias('Metadata');
45 45 }
46 46  
... ...
search2/search/search.inc.php
... ... @@ -263,6 +263,14 @@ class SearchHelper
263 263  
264 264 public static function getSavedSearches($userID)
265 265 {
  266 +
  267 + // need to test for broken db configuration so that the queries dont fail
  268 + // and so that we can be redirected to the db error page
  269 + // TODO: maybe best to have a special db error page rather than the default template when logged in
  270 +
  271 + global $default;
  272 + if (is_null($default->_db) || PEAR::isError($default->_db)) return array();
  273 +
266 274 $sql = "SELECT id, name FROM search_saved WHERE type='S'";
267 275  
268 276 // if we are not the system admin, then we get only ours or shared searches
... ... @@ -532,6 +540,52 @@ function parseExpression($expr_str)
532 540 return $parser->getExprResult();
533 541 }
534 542  
535   -
  543 +function processSearchExpression($query)
  544 +{
  545 + try
  546 + {
  547 + $expr = parseExpression($query);
  548 +
  549 + $rs = $expr->evaluate();
  550 + usort($rs, 'rank_compare');
  551 +
  552 + $results = array();
  553 + foreach($rs as $hit)
  554 + {
  555 + $item = array(
  556 + 'document_id' => (int) $hit->DocumentID,
  557 + 'title' => (string) $hit->Title,
  558 + 'relevance' => (float) $hit->Rank,
  559 + 'text' => (string) $noText?'':$hit->Text,
  560 + 'filesize' => (int) $hit->Filesize,
  561 + 'fullpath' => (string) $hit->FullPath,
  562 + 'version' => (string) $hit->Version,
  563 + 'filename' => (string) $hit->Filename,
  564 + 'checked_out_by' => (string) $hit->CheckedOutUser,
  565 + 'checked_out_date' => (string) $hit->DateCheckedOut,
  566 + 'is_available' => (bool) $hit->IsAvailable,
  567 + 'workflow' => (string) $hit->Workflow,
  568 + 'workflow_state' => (string) $hit->WorkflowState,
  569 + 'folder_id' => (int) $hit->FolderId,
  570 + 'mime_type' => (string) $hit->MimeType,
  571 + 'modified_by' => (string) $hit->ModifiedBy,
  572 + 'modified_date' => (string) $hit->DateModified,
  573 + 'created_by' => (string) $hit->CreatedBy,
  574 + 'created_date' => (string) $hit->DateCreated,
  575 + 'owner' => (string) $hit->Owner,
  576 + 'is_immutable'=> (bool) $hit->Immutable,
  577 + 'status' => (string) $hit->Status
  578 + );
  579 +
  580 + $results[] = $item;
  581 +
  582 + }
  583 + return $results;
  584 + }
  585 + catch(Exception $e)
  586 + {
  587 + return new PEAR_Error(_kt('Could not process query.') . $e->getMessage());
  588 + }
  589 +}
536 590  
537 591 ?>
538 592 \ No newline at end of file
... ...
sql/mysql/install/data.sql
No preview for this file type
templates/ktcore/login.smarty
... ... @@ -30,7 +30,13 @@
30 30 {if ($errorMessage == null)}
31 31 <p class="descriptiveText">{i18n}Please enter your details below to login.{/i18n}</p>
32 32 {else}
33   - <div class="ktErrorMessage"><span>{$errorMessage|sanitize}</span></div>
  33 + <div class="ktErrorMessage"><span>
  34 + {if ($errorMessage == $errorMessageConfirm)}
  35 + {$errorMessage}
  36 + {else}
  37 + {$errorMessage|sanitize}
  38 + {/if}
  39 + </span></div>
34 40 {/if}
35 41 <label for="username">{i18n}Username{/i18n}</label>
36 42 <input type="text" id="username" name="username"/>
... ... @@ -54,9 +60,15 @@
54 60 </div>
55 61 {/if}
56 62 <p class="descriptiveText version">
57   - {i18n}Access to this service is subject to the KnowledgeTreeLive <a href="http://www.knowledgetree.com/about/legal/live">Terms and Conditions</a> of use.{/i18n}<br/>
58   - {i18n}&copy; 2007 <a href="http://www.knowledgetree.com/">The Jam Warehouse Software (Pty) Ltd.</a> All Rights Reserved{/i18n}
59   - </p>
  63 + {i18n arg_appname="$appname"}#appname# Version{/i18n} {$versionName}<br/>
  64 + {i18n}<a href="http://www.knowledgetree.com/">Document Management Software</a>{/i18n}<br>
  65 + {i18n}&copy; 2007 <a href="http://www.knowledgetree.com/">The Jam Warehouse Software (Pty) Ltd.</a>{/i18n}<br><br>
  66 + {if ($smallVersion == 'OSS')}
  67 + {i18n}This program is free software and published under the <a href=" http://www.gnu.org/licenses/">GNU General Public License version 3</a>{/i18n}<br>
  68 + {else}
  69 + {i18n}All rights reserved.{/i18n}<br>
  70 + {/if}
  71 + </p>
60 72 <div id="bottomspacer"></div>
61 73 <div class="floatClear"></div>
62 74 </div>
... ...
templates/ktcore/manage_permissions.smarty
  1 +{literal}
  2 +<script type="text/javascript">
  3 + function populateField(value, key){
  4 + var field = document.getElementById(key);
  5 + field.value = value;
  6 + }
  7 +</script>
  8 +{/literal}
1 9 <h2>{i18n}Existing permissions{/i18n}</h2>
2 10  
3 11 <p class="descriptiveText">{i18n}Permissions are descriptors used to ascertain whether groups of users have access to certain functionality. The built-in permissions below facilitate the default functionality of the DMS and can't be changed. Plugin developers may choose to add additional permissions below that manage access to their plugins functionality.{/i18n}</p>
... ... @@ -54,4 +62,13 @@ class=&quot;ktAction ktDelete&quot;&gt;{i18n}Delete Permission{/i18n}&lt;/a&gt;
54 62 </tr>
55 63 { /foreach }
56 64 </table>
57   -
  65 +{if $context->sNameVal != ''}
  66 +<script type="text/javascript">
  67 + populateField("{$context->sNameVal}", "name");
  68 +</script>
  69 +{/if}
  70 +{if $context->sHumanNameVal != ''}
  71 +<script type="text/javascript">
  72 + populateField("{$context->sHumanNameVal}", "human_name");
  73 +</script>
  74 +{/if}
58 75 \ No newline at end of file
... ...
templates/ktcore/search2/adv_query_builder.smarty
... ... @@ -219,7 +219,7 @@ function initInt(groupid, fid)
219 219  
220 220 var nf = new Ext.form.NumberField( {allowNegative: false, decimalPrecision : 0, name: startname});
221 221 nf.render(startname);
222   - var nf2 = new Ext.form.NumberField( {allowNegative: false, decimalPrecision : 0, name: startname});
  222 + var nf2 = new Ext.form.NumberField( {allowNegative: false, decimalPrecision : 0, name: endname});
223 223 nf2.render(endname);
224 224 }
225 225  
... ... @@ -721,6 +721,7 @@ function buildExpression()
721 721 var expr = expr = fieldname + ' ' + fieldop + ' "' + start.value + '"';
722 722 switch (fieldop)
723 723 {
  724 + case 'between':
724 725 case 'BETWEEN':
725 726 expr += ' AND "' + end.value + '"';
726 727 break;
... ...
templates/ktcore/search2/lucene_statistics.smarty
1   -<P>
2   -{i18n}This dashlet provides some basic statistics from the KnowledgeTree Document Indexer.{/i18n}
3   -<P>
  1 +<html>
  2 +<head>
  3 +{literal}
  4 +<script type="text/javascript">
4 5  
  6 +function tog1(){
  7 +
  8 + var toggled = document.getElementById('expand');
  9 + var pImage = document.getElementById('id');
  10 + var mImage = document.getElementById('ie');
  11 + if(pImage.style.display == 'block'){
  12 + pImage.style.display = 'none';
  13 + mImage.style.display = 'block';
  14 + }else{
  15 + pImage.style.display = 'block';
  16 + mImage.style.display = 'none';
  17 + }
  18 + if(toggled.style.display == 'none'){
  19 + toggled.style.display = 'block';
  20 + }else{
  21 + toggled.style.display = 'none';
  22 + }
  23 +
  24 +}
  25 +
  26 +function tog2(){
  27 +
  28 + var toggle = document.getElementById('exp');
  29 + var plusImage = document.getElementById('imgd');
  30 + var minusImage = document.getElementById('imge');
  31 + if(plusImage.style.display == 'block'){
  32 + plusImage.style.display = 'none';
  33 + minusImage.style.display = 'block';
  34 + }else{
  35 + plusImage.style.display = 'block';
  36 + minusImage.style.display = 'none';
  37 + }
  38 + if(toggle.style.display == 'none'){
  39 + toggle.style.display = 'block';
  40 + }else{
  41 + toggle.style.display = 'none';
  42 + }
  43 +
  44 +}
  45 +
  46 +</script>
  47 +{/literal}
  48 +</head>
  49 +
  50 +<body>
5 51 <table>
6   -<tr><td>{i18n}Last optimisation date:{/i18n}</td><td>{$stats.optimisationDate}</td></tr>
7   -<tr><td>{i18n}Period since last optimisation:{/i18n}</td><td>{$stats.optimisationPeriod}</td></tr>
8   -<tr><td>{i18n}Last indexing date:{/i18n}</td><td>{$stats.indexingDate}</td></tr>
9   -<tr><td>{i18n}Period since last indexing:{/i18n}</td><td>{$stats.indexingPeriod}</td></tr>
10   -<tr><td>{i18n}Total documents in repository:{/i18n}</td><td>{$stats.docsInRepository}</td></tr>
11   -<tr><td>{i18n}Documents in index:{/i18n}</td><td>{$stats.docsInIndex}</td></tr>
12   -<tr><td>{i18n}Documents in indexing queue:{/i18n}</td><td>{$stats.docsInQueue}</td></tr>
13   -<tr><td>{i18n}Indexing coverage:{/i18n}</td><td>{$stats.indexingCoverage}</td></tr>
14   -<tr><td>{i18n}Queue coverage:{/i18n}</td><td>{$stats.queueCoverage}</td></tr>
  52 +<tr><td width="495px">{i18n}Last Optimization Date:{/i18n}</td><td>{$stats.optimisationDate}</td></tr>
  53 +<tr></tr>
  54 +<tr><td>{i18n}Period Since Last Optimization:{/i18n}</td><td>{$stats.optimisationPeriod}</td></tr>
  55 +<tr><td>{i18n}Last Indexing Date:{/i18n}</td><td>{$stats.indexingDate}</td></tr>
  56 +<tr><td>{i18n}Period Since Last Indexing:{/i18n}</td><td>{$stats.indexingPeriod}</td></tr>
  57 +<tr><td>{i18n}Total # Documents in Repository:{/i18n}</td><td>{$stats.docsInRepository}</td></tr>
  58 +<tr><td>{i18n}Documents Indexed:{/i18n}</td><td>{$stats.docsInIndex}</td></tr>
  59 +<tr><td>{i18n}Documents in Indexing Queue:{/i18n}</td><td>{$stats.docsInQueue}</td></tr>
  60 +<tr><td><span onclick="tog1();">
  61 +<p id="id">
  62 +<img src="{$rootUrl}/resources/graphics/bullet_toggle_plus.png" style="cursor: pointer;"/>
  63 +Index Coverage:
  64 +</p>
  65 +<p id="ie">
  66 +<img src="{$rootUrl}/resources/graphics/bullet_toggle_minus.png" style="cursor: pointer;"/>
  67 +Index Coverage:
  68 +</p>
  69 +</span>
  70 +<div id="expand" style="display: none;">
  71 +<i>{i18n}Indexing coverage percentage may vary from total - not all documents contain text.{/i18n}</i>
  72 +<br/>
  73 +</div></td><td>{$stats.indexingCoverage}</td></tr>
  74 +
  75 +
  76 +<tr><td><span onclick="tog2();">
  77 +<p id="imgd">
  78 +<img src="{$rootUrl}/resources/graphics/bullet_toggle_plus.png" style="cursor: pointer;"/>
  79 +Queue Coverage:
  80 +</p>
  81 +<p id="imge">
  82 +<img src="{$rootUrl}/resources/graphics/bullet_toggle_minus.png" style="cursor: pointer;"/>
  83 +Queue Coverage:
  84 +</p>
  85 +</span>
  86 +<div id="exp" style="display: none;">
  87 +<i>{i18n}Queue coverage indicates percentage of documents currently queued for indexing in relation to total repository size{/i18n}</i>
  88 +<br/>
  89 +</div>
  90 +</td><td>{$stats.queueCoverage}</td></tr>
  91 +
15 92 </table>
16   -<b>{i18n}Notes:{/i18n}</b><br>
  93 +
17 94 <table>
18   -<tr><td valign=top>*<td>{i18n}Not all documents contain text. This will explain why the indexing coverage percentage my vary.{/i18n}
19   -<tr><td valign=top>*<td>{i18n}The queue coverage indicates how many documents are in the queue in relation to the repository size.{/i18n}
  95 +
20 96 {if $stats.noOptimisation}
21 97 <tr><td valign=top>*<td><i>{i18n}To get the best performance out of Document Indexer, the indexes must be optimised periodically. This is managed by a background task.{/i18n}
22 98 {/if}
23 99 </table>
24 100 <table width="100%">
25 101 <tr><td colspan=2 align=right><a href="/search2.php?action=refreshLuceneStats" align=right>{i18n}Refresh{/i18n}</a></tr>
26   -</table>
27 102 \ No newline at end of file
  103 +</table>
  104 +
  105 +<script type="text/javascript">
  106 +var plusImage = document.getElementById('imgd');
  107 +var minusImage = document.getElementById('imge');
  108 +plusImage.style.display = 'block';
  109 +minusImage.style.display = 'none';
  110 +
  111 +var pImage = document.getElementById('id');
  112 +var mImage = document.getElementById('ie');
  113 +pImage.style.display = 'block';
  114 +mImage.style.display = 'none';
  115 +</script>
  116 +
  117 +</body>
  118 +</html>
28 119 \ No newline at end of file
... ...