Commit 5423af2210299fd1a312325486b59f3f810074db

Authored by Paul Barrett
2 parents 4d16f134 903ffcea

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

dmsctl.vbs
... ... @@ -159,20 +159,20 @@ Else
159 159 If (NOT isServiceStarted(svcName)) Then
160 160 If (NOT startService(svcName)) Then
161 161 isSuccess = FALSE
162   - writeLog "The " & KTOFFICE & " KnowledgeTree service could not be started. Result Code: " & lastErrorCode
  162 + writeLog "The " & KTOFFICE & " KnowledgeTree service could not be started. Result Code: " & getServiceErrorMessage(lastErrorCode)
163 163 Else
164 164 writeLog "The " & KTOFFICE & " KnowledgeTree service was successfully started"
165 165 End If
166 166  
167 167 writeLog "Successfully started " & KTOFFICE
168 168 Else
169   - writeLog KTOFFICE & " already started. Result Code: " & lastErrorCode
  169 + writeLog KTOFFICE & " already started. Result Code: " & getServiceErrorMessage(lastErrorCode)
170 170 End If
171 171  
172 172 If (isSuccess) Then
173 173 Wscript.Echo "The " & KTOFFICE & " KnowledgeTree service was successfully started"
174 174 Else
175   - Wscript.Echo "The " & KTOFFICE & " KnowledgeTree service could not be started. Result Code: " & lastErrorCode
  175 + Wscript.Echo "The " & KTOFFICE & " KnowledgeTree service could not be started. Result Code: " & getServiceErrorMessage(lastErrorCode)
176 176 End If
177 177  
178 178 Case "scheduler"
... ... @@ -181,20 +181,20 @@ Else
181 181 If (NOT isServiceStarted(svcName)) Then
182 182 If (NOT startService(svcName)) Then
183 183 isSuccess = FALSE
184   - writeLog "The " & KTSCHEDULER & " KnowledgeTree service could not be started. Result Code: " & lastErrorCode
  184 + writeLog "The " & KTSCHEDULER & " KnowledgeTree service could not be started. Result Code: " & getServiceErrorMessage(lastErrorCode)
185 185 Else
186 186 writeLog "The " & KTSCHEDULER & " KnowledgeTree service was successfully started"
187 187 End If
188 188  
189 189 writeLog "Successfully started " & KTSCHEDULER
190 190 Else
191   - writeLog KTSCHEDULER & " already started. Result Code: " & lastErrorCode
  191 + writeLog KTSCHEDULER & " already started. Result Code: " & getServiceErrorMessage(lastErrorCode)
192 192 End If
193 193  
194 194 If (isSuccess) Then
195 195 Wscript.Echo "The " & KTSCHEDULER & " KnowledgeTree service was successfully started"
196 196 Else
197   - Wscript.Echo "The " & KTSCHEDULER & " KnowledgeTree service could not be started. Result Code: " & lastErrorCode
  197 + Wscript.Echo "The " & KTSCHEDULER & " KnowledgeTree service could not be started. Result Code: " & getServiceErrorMessage(lastErrorCode)
198 198 End If
199 199  
200 200 Case "lucene"
... ... @@ -203,20 +203,20 @@ Else
203 203 If (NOT isServiceStarted(svcName)) Then
204 204 If (NOT startService(svcName)) Then
205 205 isSuccess = false
206   - writeLog "The " & KTLUCENE & " KnowledgeTree service could not be started. Result Code: " & lastErrorCode
  206 + writeLog "The " & KTLUCENE & " KnowledgeTree service could not be started. Result Code: " & getServiceErrorMessage(lastErrorCode)
207 207 Else
208 208 writeLog "The " & KTLUCENE & " KnowledgeTree service was successfully started"
209 209 End If
210 210  
211 211 writeLog "Successfully started " & KTLUCENE
212 212 Else
213   - writeLog KTLUCENE & " already started. Result Code: " & lastErrorCode
  213 + writeLog KTLUCENE & " already started. Result Code: " & getServiceErrorMessage(lastErrorCode)
214 214 End If
215 215  
216 216 If (isSuccess) Then
217 217 Wscript.Echo "The " & KTLUCENE & " KnowledgeTree service was successfully started"
218 218 Else
219   - Wscript.Echo "The " & KTLUCENE & " KnowledgeTree service could not be started. Result Code: " & lastErrorCode
  219 + Wscript.Echo "The " & KTLUCENE & " KnowledgeTree service could not be started. Result Code: " & getServiceErrorMessage(lastErrorCode)
220 220 End If
221 221 End Select
222 222 Else
... ... @@ -226,30 +226,36 @@ Else
226 226 If (NOT isServiceStarted(svcName)) Then
227 227 If (NOT startService(svcName)) Then
228 228 isSuccess = false
229   - End If
230   - writeLog "Successfully started " & KTOFFICE
  229 + writeLog "Couldn't start. " & KTOFFICE & " Result Code: " & getServiceErrorMessage(lastErrorCode)
231 230 Else
232   - writeLog KTOFFICE & " already started. Result Code: " & lastErrorCode
  231 + writeLog "Successfully started " & KTOFFICE
  232 + End If
  233 + Else
  234 + writeLog KTOFFICE & " already started. Result Code: " & getServiceErrorMessage(lastErrorCode)
233 235 End If
234 236  
235 237 svcName = KTSCHEDULER
236 238 If (NOT isServiceStarted(svcName)) Then
237 239 If (NOT startService(svcName)) Then
238 240 isSuccess = false
239   - End If
240   - writeLog "Successfully started " & KTSCHEDULER
  241 + writeLog "Couldn't start " & KTSCHEDULER & " Result Code: " & getServiceErrorMessage(lastErrorCode)
241 242 Else
242   - writeLog KTSCHEDULER & " already started. Result Code: " & lastErrorCode
  243 + writeLog "Successfully started " & KTSCHEDULER
  244 + End If
  245 + Else
  246 + writeLog KTSCHEDULER & " already started. Result Code: " & getServiceErrorMessage(lastErrorCode)
243 247 End If
244 248  
245 249 svcName = KTLUCENE
246 250 If (NOT isServiceStarted(svcName)) Then
247 251 If (NOT startService(svcName)) Then
248 252 isSuccess = false
249   - End If
250   - writeLog "Successfully started " & KTLUCENE
  253 + writeLog "Couldn't start " & KTLUCENE & " Result Code: " & getServiceErrorMessage(lastErrorCode)
251 254 Else
252   - writeLog KTLUCENE & " already started. Result Code: " & lastErrorCode
  255 + writeLog "Successfully started " & KTLUCENE
  256 + End If
  257 + Else
  258 + writeLog KTLUCENE & " already started. Result Code: " & getServiceErrorMessage(lastErrorCode)
253 259 End If
254 260  
255 261 If (isSuccess) Then
... ... @@ -267,20 +273,20 @@ Else
267 273 If (isServiceStarted(svcName)) Then
268 274 If (NOT stopService(svcName)) Then
269 275 isSuccess = false
270   - writeLog "The " & KTOFFICE & " KnowledgeTree service could not be stopped. Result Code: " & lastErrorCode
  276 + writeLog "The " & KTOFFICE & " KnowledgeTree service could not be stopped. Result Code: " & getServiceErrorMessage(lastErrorCode)
271 277 Else
272 278 writeLog "The " & KTOFFICE & " KnowledgeTree service was successfully stopped"
273 279 End If
274 280  
275 281 writeLog "Successfully stopped " & KTOFFICE
276 282 Else
277   - writeLog KTOFFICE & " already stopped. Result Code: " & lastErrorCode
  283 + writeLog KTOFFICE & " already stopped. Result Code: " & getServiceErrorMessage(lastErrorCode)
278 284 End If
279 285  
280 286 If (isSuccess) Then
281 287 Wscript.Echo "The " & KTOFFICE & " KnowledgeTree service was successfully stopped"
282 288 Else
283   - Wscript.Echo "The " & KTOFFICE & " KnowledgeTree service could not be stopped. Result Code: " & lastErrorCode
  289 + Wscript.Echo "The " & KTOFFICE & " KnowledgeTree service could not be stopped. Result Code: " & getServiceErrorMessage(lastErrorCode)
284 290 End If
285 291  
286 292 Case "scheduler"
... ... @@ -289,20 +295,20 @@ Else
289 295 If (isServiceStarted(svcName)) Then
290 296 If (NOT stopService(svcName)) Then
291 297 isSuccess = false
292   - writeLog "The " & KTSCHEDULER & " KnowledgeTree service could not be stopped. Result Code: " & lastErrorCode
  298 + writeLog "The " & KTSCHEDULER & " KnowledgeTree service could not be stopped. Result Code: " & getServiceErrorMessage(lastErrorCode)
293 299 Else
294 300 writeLog "The " & KTSCHEDULER & " KnowledgeTree service was successfully stopped"
295 301 End If
296 302  
297 303 writeLog "Successfully stopped " & KTSCHEDULER
298 304 Else
299   - writeLog KTSCHEDULER & " already stopped. Result Code: " & lastErrorCode
  305 + writeLog KTSCHEDULER & " already stopped. Result Code: " & getServiceErrorMessage(lastErrorCode)
300 306 End If
301 307  
302 308 If (isSuccess) Then
303 309 Wscript.Echo "The " & KTSCHEDULER & " KnowledgeTree service was successfully stopped"
304 310 Else
305   - Wscript.Echo "The " & KTSCHEDULER & " KnowledgeTree service could not be stopped. Result Code: " & lastErrorCode
  311 + Wscript.Echo "The " & KTSCHEDULER & " KnowledgeTree service could not be stopped. Result Code: " & getServiceErrorMessage(lastErrorCode)
306 312 End If
307 313  
308 314 Case "lucene"
... ... @@ -311,20 +317,20 @@ Else
311 317 If (isServiceStarted(svcName)) Then
312 318 If (NOT stopService(svcName)) Then
313 319 isSuccess = false
314   - writeLog "The " & KTLUCENE & " KnowledgeTree service could not be stopped. Result Code: " & lastErrorCode
  320 + writeLog "The " & KTLUCENE & " KnowledgeTree service could not be stopped. Result Code: " & getServiceErrorMessage(lastErrorCode)
315 321 Else
316 322 writeLog "The " & KTLUCENE & " KnowledgeTree service was successfully stopped"
317 323 End If
318 324  
319 325 writeLog "Successfully stopped " & KTLUCENE
320 326 Else
321   - writeLog KTLUCENE & " already stopped. Result Code: " & lastErrorCode
  327 + writeLog KTLUCENE & " already stopped. Result Code: " & getServiceErrorMessage(lastErrorCode)
322 328 End If
323 329  
324 330 If (isSuccess) Then
325 331 Wscript.Echo "The " & KTLUCENE & " KnowledgeTree service was successfully stopped"
326 332 Else
327   - Wscript.Echo "The " & KTLUCENE & " KnowledgeTree service could not be stopped. Result Code: " & lastErrorCode
  333 + Wscript.Echo "The " & KTLUCENE & " KnowledgeTree service could not be stopped. Result Code: " & getServiceErrorMessage(lastErrorCode)
328 334 End If
329 335 End Select
330 336 Else
... ... @@ -335,30 +341,36 @@ Else
335 341 If (isServiceStarted(svcName)) Then
336 342 If (NOT stopService(svcName)) Then
337 343 isSuccess = false
338   - End If
339   - writeLog "Successfully stopped " & KTOFFICE
  344 + writeLog "Couldn't stop." & KTOFFICE & " Result Code: " & getServiceErrorMessage(lastErrorCode)
340 345 Else
341   - writeLog KTOFFICE & " already stopped. Result Code: " & lastErrorCode
  346 + writeLog "Successfully stopped " & KTOFFICE
  347 + End If
  348 + Else
  349 + writeLog KTOFFICE & " already stopped. Result Code: " & getServiceErrorMessage(lastErrorCode)
342 350 End If
343 351  
344 352 svcName = KTSCHEDULER
345 353 If (isServiceStarted(svcName)) Then
346 354 If (NOT stopService(svcName)) Then
347 355 isSuccess = false
348   - End If
349   - writeLog "Successfully stopped " & KTSCHEDULER
  356 + writeLog "Couldn't stop." & KTSCHEDULER & " Result Code: " & getServiceErrorMessage(lastErrorCode)
350 357 Else
351   - writeLog KTSCHEDULER & " already stopped. Result Code: " & lastErrorCode
  358 + writeLog "Successfully stopped " & KTSCHEDULER
  359 + End If
  360 + Else
  361 + writeLog KTSCHEDULER & " already stopped. Result Code: " & getServiceErrorMessage(lastErrorCode)
352 362 End If
353 363  
354 364 svcName = KTLUCENE
355 365 If (isServiceStarted(svcName)) Then
356 366 If (NOT stopService(svcName)) Then
357 367 isSuccess = false
358   - End If
359   - writeLog "Successfully stopped " & KTLUCENE
  368 + writeLog "Couldn't stop." & KTLUCENE & " Result Code: " & getServiceErrorMessage(lastErrorCode)
360 369 Else
361   - writeLog KTLUCENE & " already stopped. Result Code: " & lastErrorCode
  370 + writeLog "Successfully stopped " & KTLUCENE
  371 + End If
  372 + Else
  373 + writeLog KTLUCENE & " already stopped. Result Code: " & getServiceErrorMessage(lastErrorCode)
362 374 End If
363 375  
364 376 If (isSuccess) Then
... ... @@ -669,3 +681,59 @@ Public Sub writeLog(ByVal strMessage)
669 681 objTextFile.Close
670 682 End Sub
671 683  
  684 +Public Function getServiceErrorMessage(ByVal errCode)
  685 + Select Case errCode
  686 + Case SVC_SUCCESS
  687 + getServiceErrorMessage = "Success"
  688 + Case SVC_NOT_SUPPORTED
  689 + getServiceErrorMessage = "Not Supported"
  690 + Case SVC_ACCESS_DENIED
  691 + getServiceErrorMessage = "Access Denied"
  692 + Case SVC_DEPENDENT_SERVICES_RUNNING
  693 + getServiceErrorMessage = "Dependent Services Running"
  694 + Case SVC_INVALID_SERVICE_CONTROL
  695 + getServiceErrorMessage = "Invalid Service Control"
  696 + Case SVC_SERVICE_CANNOT_ACCEPT_CONTROL
  697 + getServiceErrorMessage = "Service Cannot Accept Control"
  698 + Case SVC_SERVICE_NOT_ACTIVE
  699 + getServiceErrorMessage = "Service Not Active"
  700 + Case SVC_SERVICE_REQUEST_TIMEOUT
  701 + getServiceErrorMessage = "Service Request Timeout"
  702 + Case SVC_UNKNOWN_FAILURE
  703 + getServiceErrorMessage = "Unknown Failure"
  704 + Case SVC_PATH_NOT_FOUND
  705 + getServiceErrorMessage = "Path Not Found"
  706 + Case SVC_SERVICE_ALREADY_RUNNING
  707 + getServiceErrorMessage = "Service Already Running"
  708 + Case SVC_SERVICE_DATABASE_LOCKED
  709 + getServiceErrorMessage = "Service Database Locked"
  710 + Case SVC_SERVICE_DEPENDENCY_DELETED
  711 + getServiceErrorMessage = "Service Dependency Deleted"
  712 + Case SVC_SERVICE_DEPENDENCY_FAILURE
  713 + getServiceErrorMessage = "Service Dependency Failure"
  714 + Case SVC_SERVICE_DISABLED
  715 + getServiceErrorMessage = "Service Disabled"
  716 + Case SVC_SERVICE_LOGON_FAILURE
  717 + getServiceErrorMessage = "Service Logon Failure"
  718 + Case SVC_SERVICE_MARKED_FOR_DELETION
  719 + getServiceErrorMessage = "Service Marked For Deletion"
  720 + Case SVC_SERVICES_NO_THREAD
  721 + getServiceErrorMessage = "Service No Thread"
  722 + Case SVC_STATUS_CIRCULAR_DEPENDENCY
  723 + getServiceErrorMessage = "Status Circular Dependency"
  724 + Case SVC_STATUS_DUPLICATE_NAME
  725 + getServiceErrorMessage = "Status Duplicate Name"
  726 + Case SVC_INVALID_NAME
  727 + getServiceErrorMessage = "Status Invalid Name"
  728 + Case SVC_STATUS_INVALID_PARAMETER
  729 + getServiceErrorMessage = "Status Invalid Parameter"
  730 + Case SVC_INVALID_SERVICES_ACCOUNT
  731 + getServiceErrorMessage = "Status Invalid Service Account"
  732 + Case SVC_STATUS_SERVICE_EXISTS
  733 + getServiceErrorMessage = "Status Service Exists"
  734 + Case SVC_SERVICE_ALREADY_PAUSED
  735 + getServiceErrorMessage = "Service Already Paused"
  736 + Case Else
  737 + getServiceErrorMessage = "Unknown Failure"
  738 + End Select
  739 +End Function
... ...
plugins/ktstandard/documentpreview/documentPreview.php
... ... @@ -176,7 +176,11 @@ class DocumentPreview {
176 176  
177 177 $sInfo = $this->getMetadata();
178 178  
179   - return '<div id="preview" class="preview" onclick="javascript: destroyPanel();">'.$sInfo.'</div>';
  179 + $sInfo = '<div id="preview" class="preview" onclick="javascript: destroyPanel();">'.$sInfo.'</div>';
  180 +
  181 + $sInfo .= $this->getThumbnail();
  182 +
  183 + return $sInfo;
180 184 }
181 185  
182 186 /**
... ... @@ -280,8 +284,6 @@ class DocumentPreview {
280 284 $sInfo .= "<tr><td>{$sIdLb}</td><td><b>{$sId}</b></td></tr>";
281 285 $sInfo .= " </table></div>";
282 286  
283   - $sInfo .= $this->getThumbnail();
284   -
285 287 return $sInfo;
286 288 }
287 289  
... ...
setup/migrate/steps/migrateDatabase.php
... ... @@ -171,7 +171,7 @@ class migrateDatabase extends Step
171 171 $cmd = $exe.' -u"'.$dbAdminUser.'" -p"'.$dbAdminPass.'" --port="'.$port.'" '.$dbName.' > '.$sqlFile;
172 172 if($noFile) {
173 173 $this->error[]['error'] = "The KnowledgeTree Setup Wizard was unable to connect to your KnowledgeTree 3.6.1 database.";
174   - $this->error[]['msg'] = "Please ensure that all KnowledgeTree Services are running.";
  174 + $this->error[]['msg'] = "Please ensure that your KnowledgeTree Mysql service is running.";
175 175 $this->error[]['cmd'] = "Click <b>Next</b> after resolving the above errors.";
176 176 $this->temp_variables['manual_export'] = "";
177 177 } else {
... ...
setup/upgrade/steps/upgradeBackup.php
... ... @@ -208,7 +208,7 @@ class upgradeBackup extends Step {
208 208 $prefix = '';
209 209 if (!WINDOWS_OS)
210 210 {
211   - $prefix .= "./";
  211 + $prefix .= "";//$prefix .= "./";
212 212 }
213 213  
214 214 if (@stat($dbSocket) !== false)
... ...
setup/upgrade/templates/complete.tpl
... ... @@ -20,7 +20,8 @@
20 20 <br/>
21 21 <br/>
22 22 <?php } else { ?>
23   - To start the services, execute the dmsctl.bat batch file in the KnowledgeTree directory from a command prompt, run as administrator.
  23 + To start the services, using the instructions below:
  24 +<!-- execute the dmsctl.bat batch file in the KnowledgeTree directory from a command prompt, run as administrator.-->
24 25 <br/>
25 26 <br/>
26 27 <?php } ?>
... ... @@ -30,11 +31,11 @@
30 31 <br/>
31 32 [START MENU] => [Programs] => [KnowledgeTree 3.7.x] => [services]
32 33 <br/>
33   - Click [Install Services]
  34 + Right-Click and run [Install Services] as administrator
34 35 <br/>
35 36 [START MENU] => [Programs] => [KnowledgeTree 3.7.x] => [services]
36 37 <br/>
37   - Click [Start Services]
  38 + Right-Click and run [Start Services] as administrator
38 39 <br/>
39 40 <br/>
40 41 <b>Alternatively:</b>
... ...
setup/wizard/lib/services/unixLucene.php
... ... @@ -201,6 +201,7 @@ class unixLucene extends unixService {
201 201 */
202 202 public function start() {
203 203 $state = $this->status();
  204 + $this->writeLuceneProperties();
204 205 if($state != 'STARTED') {
205 206 //$logFile = $this->outputDir."lucene.log";
206 207 $logFile = "/dev/null";//$this->outputDir."lucene.log";
... ... @@ -232,5 +233,29 @@ class unixLucene extends unixService {
232 233 return "";//"Execute from terminal : $installDir/dmsctl.sh stop";
233 234 }
234 235  
  236 + /**
  237 + * Write Lucene Service property file
  238 + *
  239 + * @author KnowledgeTree Team
  240 + * @access public
  241 + * @param none
  242 + * @return string
  243 + */
  244 + private function writeLuceneProperties() {
  245 + // Check if bin is readable and writable
  246 + $fileLoc = $this->getluceneDir()."KnowledgeTreeIndexer.properties";
  247 + $fp = fopen($fileLoc, "w+");
  248 + $content = "server.port=8875\n";
  249 + $content .= "server.paranoid=false\n";
  250 + $content .= "server.accept=127.0.0.1\n";
  251 + $content .= "server.deny=\n";
  252 + $conf = $this->util->getDataFromSession('configuration');
  253 + $varDirectory = $conf['paths']['varDirectory']['path'];
  254 + $content .= "indexer.directory=$varDirectory\n";
  255 + $content .= "indexer.analyzer=org.apache.lucene.analysis.standard.StandardAnalyzer\n";
  256 + fwrite($fp, $content);
  257 + fclose($fp);
  258 + @chmod($fileLoc, 0644);
  259 + }
235 260 }
236 261 ?>
237 262 \ No newline at end of file
... ...
setup/wizard/templates/complete.tpl
... ... @@ -23,7 +23,8 @@
23 23 <br/>
24 24 <br/>
25 25 <?php } else { ?>
26   - To start the services, execute the dmsctl.bat batch file in the KnowledgeTree directory from a command prompt, run as administrator.
  26 + To start the services, using the instructions below:
  27 +<!-- execute the dmsctl.bat batch file in the KnowledgeTree directory from a command prompt, run as administrator.-->
27 28 <br/>
28 29 <br/>
29 30 <?php } ?>
... ... @@ -33,11 +34,11 @@
33 34 <br/>
34 35 [START MENU] => [Programs] => [KnowledgeTree 3.7.x] => [services]
35 36 <br/>
36   - Click [Install Services]
  37 + Right-Click and run [Install Services] as administrator
37 38 <br/>
38 39 [START MENU] => [Programs] => [KnowledgeTree 3.7.x] => [services]
39 40 <br/>
40   - Click [Start Services]
  41 + Right-Click and run [Start Services] as administrator
41 42 <br/>
42 43 <br/>
43 44 <b>Alternatively:</b>
... ...
webservice/clienttools/services/0.9/auth.php 0 → 100644
  1 +<?php
  2 +
  3 +class auth extends client_service {
  4 +
  5 + public function login(){
  6 + $params=$this->AuthInfo;
  7 +
  8 + $username=$params['user'];
  9 + $passhash=$params['passhash'];
  10 + $token=$params['token'];
  11 + $app_type=$params['appType'];
  12 + $session_id=$params['session'];
  13 + $ip=$_SERVER['REMOTE_ADDR'];
  14 + $language=isset($params['language'])?$params['language']:'en';
  15 +
  16 + $this->Response->setDebug('parameters',$params);
  17 +
  18 + setcookie("kt_language", $language, 2147483647, '/');
  19 +
  20 + $kt =& $this->KT;
  21 +
  22 + if ($username != 'admin') {
  23 + //$this->addDebug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@','');
  24 +
  25 + try{
  26 + if(class_exists('BaobabKeyUtil')){
  27 + if (!BaobabKeyUtil::checkIfLicensed(true)) {
  28 + $this->setResponse(array('authenticated'=> false, 'message'=> 'license_expired'));
  29 + $this->addError('Licence Expired');
  30 + return false;
  31 + }
  32 + }else{
  33 + $this->addError('Licence Utility could not be loaded. Appears to be a Community version.');
  34 + $this->setResponse(array('authenticated'=> false, 'message'=> 'Licence Utility could not be loaded. Appears to be a Community version.'));
  35 + return false;
  36 + }
  37 + }catch(Exception $e){
  38 + $this->addError('could not execute BaobabKeyUtil::checkIfLicensed');
  39 + $this->setResponse(array('authenticated'=> false, 'message'=> 'BaobabKeyUtil::checkIfLicensed error'));
  40 + return;
  41 + }
  42 + }
  43 +
  44 + $user=$kt->get_user_object_by_username($username);
  45 + if(!PEAR::isError($user)){
  46 + $password=$user->getPassword();
  47 + $localPassHash=md5($password.$token);
  48 + if($localPassHash==$passhash){
  49 + $session=new stdClass();
  50 + $this->Response->setDebug('trying to start session with',array('username'=>$username,'password'=>$password));
  51 + $session = $kt->start_session($username, $params['pass'],NULL,$app_type);
  52 + if(!PEAR::isError($session)){
  53 + $this->Response->setStatus('session_id',$session->get_session());
  54 + }else{
  55 + $this->setResponse(array('authenticated'=> false, 'message'=> 'Invalid username and/or password.'));
  56 + $this->addDebug('failed login',print_r($session,true));
  57 + $this->addError('Unknown Login Error');
  58 + return false;
  59 + }
  60 + }else{
  61 + $this->addError('Incorrect Credentials');
  62 + //throw new Exception('Incorrect Credentials');
  63 + return false;
  64 + }
  65 + }else{
  66 + $this->addError('Incorrect Credentials');
  67 + //throw new Exception('Unrecognized User');
  68 + return false;
  69 + }
  70 + return true;
  71 + }
  72 +
  73 + public function japiLogin(){
  74 + global $default;
  75 +
  76 + $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']);
  77 + $ret=array(
  78 + 'fullName' =>PEAR::isError($user)?'':$user->getName()
  79 + );
  80 + $this->setResponse($ret);
  81 + return true;
  82 + }
  83 +
  84 + public function pickup_session(){
  85 + $params=$this->AuthInfo;
  86 + $app_type=$params['appType'];
  87 + $session_id=$params['session'];
  88 + $ip=$_SERVER['REMOTE_ADDR'];
  89 +
  90 + $session = $this->KT->get_active_session($session_id, $ip, $app_type);
  91 +
  92 + if (PEAR::isError($session)){
  93 + return false;
  94 + }
  95 + $this->Response->setStatus('session_id',$session->get_session());
  96 + return true;
  97 + }
  98 +
  99 +
  100 + public function ping(){
  101 + global $default;
  102 + $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']);
  103 + $versions=$this->handler->getServerVersions();
  104 + $bestVer=$versions[count($versions)-1];
  105 + $clientVer=$this->handler->getVersion();
  106 + $ret=array(
  107 + 'response' =>'pong',
  108 + 'loginLocation' => '/index.html',
  109 + 'versionok' =>in_array($clientVer,$versions),
  110 + 'fullName' =>PEAR::isError($user)?'':$user->getName(),
  111 + 'serverVersions' =>$versions,
  112 + 'serverBestVersion' =>$bestVer,
  113 + 'clientVersion' =>$clientVer,
  114 + 'canUpgradeClient' =>($clientVer<$bestVer?true:false),
  115 + 'canUpgradeServer' =>($clientVer>$bestVer?true:false)
  116 +
  117 + );
  118 + $this->setResponse($ret);
  119 + return true;
  120 + }
  121 +
  122 + function logout($params){
  123 + $params=$this->AuthInfo;
  124 + $app_type=$params['appType'];
  125 + $session_id=$params['session'];
  126 + $ip=$_SERVER['REMOTE_ADDR'];
  127 +
  128 + $session = $this->KT->get_active_session($session_id, $ip, $app_type);
  129 +
  130 + if (PEAR::isError($session)){
  131 + return false;
  132 + }
  133 +
  134 + $session->logout();
  135 + $this->setResponse(array('logout'=>true));
  136 + return true;
  137 + }
  138 +
  139 +}
  140 +
  141 +?>
0 142 \ No newline at end of file
... ...
webservice/clienttools/services/0.9/kt.php 0 → 100644
  1 +<?php
  2 +class kt extends client_service {
  3 +
  4 +
  5 +
  6 +/**
  7 + * Get Supported (?) Languages
  8 + *
  9 + * returns array containing languages, count, & defaultlanguage
  10 + *
  11 + */
  12 + function get_languages($passthru=false){
  13 + global $default;
  14 + $oReg =& KTi18nregistry::getSingleton();
  15 + $aRegisteredLangs=$oReg->geti18nLanguages('knowledgeTree');
  16 + $aLanguageNames=$oReg->getLanguages('knowledgeTree');
  17 + $languages=array();
  18 +
  19 + if(!empty($aRegisteredLangs)){
  20 + foreach (array_keys($aRegisteredLangs) as $sLang){
  21 + $languages[]=array(
  22 + 'isoCode'=>$sLang,
  23 + 'language'=>$aLanguageNames[$sLang]
  24 + );
  25 + }
  26 + }
  27 + $response=array('languages'=>$languages, 'count'=>count($languages), 'defaultLanguage'=>$default->defaultLanguage);
  28 + if(is_bool($passthru))if($passthru)return $response;
  29 + $this->setResponse($response);
  30 + }
  31 +
  32 +
  33 + function get_rootfolder_detail($params){
  34 + $params['folderId']='1';
  35 + $this->get_folder_detail($params);
  36 + }
  37 +
  38 +
  39 + function get_folder_detail($params) {
  40 + if(isset($params['node'])&&!isset($params['folderId'])){
  41 + $params['node']=split('_',$params['node']);
  42 + $params['folderId']=$params['node'][1];
  43 + }
  44 + $kt=&$this->KT;
  45 +
  46 + $folder=&$kt->get_folder_by_id($params['folderId']);
  47 + if (PEAR::isError($folder))
  48 + {
  49 + $this->setError("Could not get folder by Id: {$params['folderId']}");
  50 + $this->setDebug('FolderError',array('kt'=>$kt,'folder'=>$folder));
  51 + return false;
  52 + }
  53 +
  54 + $detail=$folder->get_detail();
  55 + if (PEAR::isError($detail)){
  56 + $this->setResponse("detail error {$params['node']}");
  57 + return false;
  58 + }
  59 +
  60 + if(strtolower($detail['folder_name'])=='root folder'){
  61 + $detail['folder_name']='KnowledgeTree';
  62 + }
  63 +
  64 + $qtip .= $this->xlate('Folder name').": {$detail['folder_name']}<br>";
  65 + $class='folder';
  66 +
  67 + $permissions=$detail['permissions'];
  68 + $perms='';
  69 + $canWrite=false;
  70 +
  71 + for ($j=0; $j < strlen($permissions); $j++){
  72 + switch (strtoupper($permissions{$j})){
  73 + case 'W':
  74 + $canWrite=true;
  75 + $perms .= $this->xlate('write, ');
  76 + break;
  77 + case 'R':
  78 + $perms .= $this->xlate('read, ');
  79 + break;
  80 + case 'A':
  81 + $perms .= $this->xlate('add folder, ');
  82 + break;
  83 + }
  84 + }
  85 +
  86 + if (strlen($perms) > 2){
  87 + $perms=substr($perms, 0, strlen($perms)-2);
  88 + }
  89 +
  90 + $qtip .= $this->xlate('Permissions:') . " {$perms}<br>";
  91 + $qtip .= $canWrite ? $this->xlate('You may add content to this folder') : $this->xlate('You may not add content to this folder');
  92 +
  93 + $result[]=array(
  94 + 'text'=>$detail['folder_name'],
  95 + 'id'=>'F_'. $params['folderId'],
  96 + 'filename'=>$detail['folder_name'],
  97 + 'cls'=>'folder',
  98 + 'leaf'=>false,
  99 + 'document_type'=>'',
  100 + 'item_type'=>'F',
  101 + 'permissions'=>$permissions,
  102 + 'qtip'=> $qtip
  103 + );
  104 +
  105 + $this->setResponse($result);
  106 + return true;
  107 + }
  108 +
  109 +
  110 + function get_folder_contents($params){
  111 + $kt=&$this->KT;
  112 +
  113 + $params['control']='F_';
  114 + $params['node']=substr($params['node'], strlen($params['control']));
  115 +
  116 + $folder=&$kt->get_folder_by_id($params['node']);
  117 + if(!$this->checkPearError($folder,"[error 1] Folder Not Found: {$params['control']}{$params['node']}",'',array()))return false;
  118 +
  119 + $types=(isset($params['types']) ? $params['types'] : 'DF');
  120 + $listing=$folder->get_listing(1, $types);
  121 + $result=$this->_processListing($listing, 'folderContents', $params);
  122 +
  123 + $this->setResponse($result);
  124 + return true;
  125 + }
  126 +
  127 +
  128 + /**
  129 + * Returns the contents of a folder formatted for a grid view.
  130 + *
  131 + * @param array $arr
  132 + * @return array
  133 + */
  134 + function get_folder_contents_for_grid($arr)
  135 + {
  136 + $kt=&$this->KT;
  137 +
  138 + $arr['control']='F_';
  139 + $arr['node']=substr($arr['node'], strlen($arr['control']));
  140 +
  141 + $folder=&$kt->get_folder_by_id($arr['node']);
  142 + if (PEAR::isError($folder)){
  143 + echo '<pre>'.print_r($arr,true).'</pre>';
  144 + $this->addError('Folder Not found');
  145 + return false;
  146 + }
  147 +
  148 + $types=(isset($arr['types']) ? $arr['types'] : 'DF');
  149 +
  150 + $listing=$folder->get_listing(1, $types);
  151 +
  152 + $result=$this->_processListing($listing, 'grid', $arr);
  153 +
  154 + $this->setResponse(array('totalCount'=>count($listing), 'items'=>$result));
  155 +
  156 + return true;
  157 + }
  158 +
  159 +
  160 +
  161 + private function _processListing($listing, $type, $arr){
  162 + $result=array();
  163 + $methodToIncludeItem='_processItemInclusion_'.$type;
  164 +
  165 + foreach($listing as $item){
  166 + /* Trying to fix folder sizes */
  167 + if($item['filesize']<=0){
  168 + $item['filesize']='';
  169 + }else{
  170 + $item['filesize']=serviceHelper::size_readable($item['filesize']);
  171 + }
  172 +
  173 + $filename=$item['filename'];
  174 + $itemType=$item['item_type'];
  175 +
  176 + $includeMe=true;
  177 + $qtip='';
  178 + $canWrite=false;
  179 + $immutable=false;
  180 + $permissions=$item['permissions'];
  181 + $perms='';
  182 +
  183 + for ($j=0; $j < strlen($permissions); $j++){
  184 + switch (strtoupper($permissions{$j})){
  185 + case 'W':
  186 + $canWrite=true;
  187 + $perms .= $this->xlate('write, ');
  188 + break;
  189 + case 'R':
  190 + $perms .= $this->xlate('read, ');
  191 + break;
  192 + case 'A':
  193 + $perms .= $this->xlate('add folder, ');
  194 + break;
  195 + }
  196 + }
  197 +
  198 + if(strlen($perms) > 2){
  199 + $perms=substr($perms, 0, strlen($perms)-2);
  200 + }
  201 +
  202 + if($itemType=='F'){
  203 + $qtip .= $this->xlate('Folder name').": {$filename}<br>";
  204 + $class='folder';
  205 + $qtip .= $this->xlate('Permissions:') . " {$perms}<br>";
  206 + $qtip .= $canWrite ? $this->xlate('You may add content to this folder') : $this->xlate('You may not add content to this folder');
  207 + }
  208 +
  209 + //documents
  210 + else{
  211 + $qtip='';
  212 + $extpos=strrpos($filename, '.') ;
  213 +
  214 + if($extpos === false){
  215 + $class='file-unknown';
  216 + }else{
  217 + $ext=substr($filename, $extpos); // Get Extension including the dot
  218 + $class='file-' . substr($filename, $extpos +1); // Get Extension without the dot
  219 + }
  220 +
  221 + $extensions=explode(',', $arr['extensions']);
  222 + if(!in_array(strtolower($ext), $extensions) && !in_array('*',$extensions)){
  223 + $includeMe=false;
  224 + }else{
  225 + $qtip .= $this->xlate('Filename') . ": {$filename}<br>";
  226 + $qtip .= $this->xlate('File Size') . ": " . serviceHelper::fsize_desc($item['filesize']) . "<br>";
  227 + $qtip .= $this->xlate('Modified') . ": {$item['modified_date']}<br>";
  228 + $qtip .= $this->xlate('Owner') . ": {$item['created_by']}<br>";
  229 + $qtip .= $this->xlate('Version') . ": {$item['version']}<br>";
  230 + if (serviceHelper::bool2str(strtolower($item['is_immutable']))=='true'){
  231 + $canWrite=false;
  232 + $immutable=true;
  233 + }
  234 +
  235 + if($immutable){
  236 + $qtip .= $this->xlate('Status: Immutable') . '<br>';
  237 + }else if (strtolower($item['checked_out_by']) != 'n/a' && ($item['checked_out_by'] != '')){
  238 + $qtip .= $this->xlate('Status: Checked out by') . " {$item['checked_out_by']}<br>";
  239 + }else{
  240 + $qtip .= $this->xlate('Status: Available') . '<br>';
  241 + }
  242 + $qtip .= $this->xlate('Permissions:') . " {$perms}<br>";
  243 +
  244 + if($immutable){
  245 + $qtip .= $this->xlate('This document is not editable');
  246 + }else if ($canWrite){
  247 + $qtip .= $this->xlate('You may edit this document');
  248 + }else{
  249 + $qtip .= $this->xlate('This document is not editable');
  250 + }
  251 + }
  252 + }//end of if for files
  253 + if($includeMe){
  254 + $result[]=$this->$methodToIncludeItem($item, $class, $qtip);
  255 + }
  256 + }
  257 + return $result;
  258 + }
  259 +
  260 +
  261 +
  262 +
  263 + private function _processItemInclusion_folderContents($item, $class, $qtip){
  264 + return array (
  265 + 'text'=>htmlspecialchars($item['title']),
  266 + 'originaltext'=>$item['title'],
  267 + 'id'=>($item['item_type']=='F' ? $item['item_type']."_" : "").$item['id'],
  268 + 'filename'=>$item['filename'],
  269 + 'cls'=>$class,
  270 + 'leaf'=>($item['item_type']=='D'),
  271 + 'document_type'=>$item['document_type'],
  272 + 'item_type'=>$item['item_type'],
  273 + 'permissions'=>$item['permissions'],
  274 + 'content_id'=>$item['content_id'],
  275 + 'checked_out_by'=>$item['checked_out_by'],
  276 + 'qtip'=> $qtip
  277 + );
  278 + }
  279 +
  280 +
  281 + private function _processItemInclusion_search($item, $class, $qtip)
  282 + {
  283 + if ($item['filesize']=='n/a') {
  284 + $item['filesize']=-1;
  285 + }
  286 + return array (
  287 + 'text'=>htmlspecialchars($item['title']),
  288 + 'originaltext'=>$item['title'],
  289 + 'id'=>$item['document_id'],
  290 + 'filename'=>$item['filename'],
  291 + 'cls'=>$class,
  292 + 'leaf'=>true,
  293 + 'document_type'=>$item['document_type'],
  294 + 'item_type'=>'D',
  295 + 'permissions'=>$item['permissions'],
  296 + 'content_id'=>$item['content_id'],
  297 + 'filesize'=>$item['filesize'],
  298 + 'modified'=>$item['modified_date'],
  299 + 'created_date'=>$item['created_date'],
  300 + 'checked_out_by'=>$item['checked_out_by'],
  301 + 'relevance'=>$item['relevance'],
  302 + 'qtip'=> $qtip,
  303 + 'version'=>$item['version']
  304 + );
  305 + }
  306 +
  307 + private function _processItemInclusion_grid($item, $class, $qtip)
  308 + {
  309 + //var_dump($item);
  310 +
  311 + if ($item['filesize']=='n/a') {
  312 + $item['filesize']=-1;
  313 + }
  314 +
  315 + return array (
  316 + 'text'=>htmlspecialchars($item['title']),
  317 + 'originaltext'=>$item['title'],
  318 + 'id'=>$item['id'],
  319 + 'filename'=>$item['filename'],
  320 + 'cls'=>$class,
  321 + 'owner'=>$item['created_by'],
  322 + 'document_type'=>$item['document_type'],
  323 + 'item_type'=>$item['item_type'],
  324 + 'permissions'=>$item['permissions'],
  325 + 'created_date'=>$item['created_date'],
  326 + 'content_id'=>$item['content_id'],
  327 + 'filesize'=>$item['filesize'],
  328 + 'modified'=>$item['modified_date'],
  329 + 'checked_out_by'=>$item['checked_out_by'],
  330 + 'version'=>$item['version']
  331 + );
  332 + }
  333 +
  334 +
  335 + public function get_metadata($params) {
  336 + $kt=&$this->KT;
  337 +
  338 + if (substr($params['document_id'], 0, 2)=='D_') {
  339 + $params['document_id']=substr($params['document_id'], 2);
  340 + }
  341 +
  342 + $document_id=(int)$params['document_id'];
  343 + if($document_id > 0) {
  344 + $document=$kt->get_document_by_id($params['document_id']);
  345 + $detail=$document->get_metadata();
  346 + $document_detail=$document->get_detail();
  347 + $title=$document_detail['title'];
  348 + $document_type=$document_detail['document_type'];
  349 +
  350 + }else{
  351 + if(isset($params['document_type'])) {
  352 + $document_type=$params['document_type'];
  353 + }else{
  354 + $document_type='Default';
  355 + }
  356 + $detail=$kt->get_document_type_metadata($document_type);
  357 + $title="";
  358 + }
  359 +
  360 + $result=array();
  361 + $items=array();
  362 + $index=0;
  363 + $items[]=array("name"=>"__title", "index"=>0, "value"=>$title, "control_type"=>"string");
  364 +
  365 +
  366 + // Commented out for timebeing - will be used by 'Save in Format'
  367 +
  368 + if (isset($params['extensions'])) {
  369 +
  370 + $fileParts=pathinfo($document_detail['filename']);
  371 +
  372 + $items[]=array("name"=>"__document_extension", "index"=>0, "value"=>strtolower($fileParts['extension']), "control_type"=>"lookup", "selection"=>explode(',', str_replace('.', '', $params['extensions'])));
  373 + }
  374 +
  375 + $document_types=$kt->get_documenttypes($params);
  376 + $items[]=array("name"=>"__document_type", "index"=>0, "value"=>$document_type, "control_type"=>"lookup", "selection"=>$document_types);
  377 +
  378 + foreach ($detail as $fieldset) {
  379 + foreach ($fieldset['fields'] as $field) {
  380 +
  381 + $prepArray = array(
  382 + 'fieldset' => $fieldset['fieldset'],
  383 + 'name' => $field['name'],
  384 +
  385 + // Change for value. If blank value is set to 1, change value to ''
  386 + // Overcomes issue of n/a
  387 + 'value' => ($document_id > 0 ? ($field['blankvalue'] == '1' ? '' : $field['value']) : ''),
  388 +
  389 + 'description' => $field['description'],
  390 + 'control_type' => $field['control_type'],
  391 + 'selection' => $field['selection'],
  392 + 'required' => $field['required'],
  393 + 'blankvalue' => $field['blankvalue'],
  394 + 'index' => $index
  395 + );
  396 +
  397 + // Small Adjustment for multiselect to real type
  398 + if ($field['control_type'] == 'multiselect') {
  399 + $prepArray['control_type'] = $field['options']['type'];
  400 + }
  401 +
  402 +
  403 + if (isset($field['options']['ishtml'])) {
  404 + $prepArray['ishtml'] = $field['options']['ishtml'];
  405 + } else {
  406 + $prepArray['ishtml'] = '0';
  407 + }
  408 +
  409 + if (isset($field['options']['maxlength'])) {
  410 + $prepArray['maxlength'] = $field['options']['maxlength'];
  411 + } else {
  412 + $prepArray['maxlength'] = '-1';
  413 + }
  414 +
  415 + $items[] = $prepArray;
  416 + $index++;
  417 + }
  418 + }
  419 +
  420 +
  421 +
  422 + $this->setResponse(array('id'=>$title, 'items'=>$items, 'count'=>count($items)));
  423 +
  424 + return true;
  425 + }
  426 +
  427 +
  428 + public function get_documenttypes($params) {
  429 +
  430 + $kt=&$this->KT;
  431 +
  432 + $detail=$kt->get_documenttypes();
  433 + $result=array();
  434 + $items=array();
  435 + for($i=0;$i<count($detail);$i++) {
  436 + if(strtolower(substr($detail[$i], -5)) != 'email')
  437 + {
  438 + $items[]=array(
  439 + 'name'=>$detail[$i]
  440 + );
  441 + }
  442 + }
  443 + $this->setResponse(array('items'=>$items, 'count'=>count($items)));
  444 + return true;
  445 + }
  446 +
  447 + function update_document_type($params) {
  448 + $kt=&$this->KT;
  449 + $document_id=(int)$params['document_id'];
  450 + if($document_id > 0) {
  451 + $document=$kt->get_document_by_id($document_id);
  452 + $document->change_document_type($params['document_type']);
  453 + $this->setResponse(array('status_code'=>0));
  454 + return true;
  455 +
  456 + }else{
  457 + $this->addError("Invalid document Id : {$document_id}");
  458 + $this->setResponse(array('status_code'=>1));
  459 + return false;
  460 + }
  461 +
  462 + }
  463 +
  464 + /**
  465 + * Get a url for downloading the specified document
  466 + * Parameters:
  467 + * session_id
  468 + * app_type
  469 + * document_id
  470 + *
  471 + * @param unknown_type $params
  472 + */
  473 + function download_document($params,$returnResult=false) {
  474 +
  475 + $kt=&$this->KT;
  476 + $params['session_id']=$params['session_id']?$params['session_id']:$this->AuthInfo['session'];
  477 + $params['app_type']=$params['app_type']?$params['app_type']:$this->AuthInfo['appType'];
  478 + $params['app_type']='air';
  479 + $multipart=isset($params['multipart'])?(bool)$params['multipart']:false;
  480 +
  481 + $this->addDebug('parameters',$params);
  482 +
  483 +
  484 + $session_id=$params['session_id'];
  485 +
  486 +
  487 + $document=&$kt->get_document_by_id($params['document_id']);
  488 + // $docname='test.txt';
  489 + if (PEAR::isError($document))
  490 + {
  491 + $response['message']=$document->getMessage();
  492 + //$this->addDebug("download_document - cannot get $document_id - " . $document->getMessage(), $session_id);
  493 +
  494 +// $this->setResponse(new SOAP_Value('$this->response=',"{urn:$this->namespace}kt_response", $response));
  495 + $this->setResponse($response);
  496 + return;
  497 + }
  498 + $docname=$document->document->getFileName();
  499 + $result=$document->download();
  500 + if (PEAR::isError($result))
  501 + {
  502 + $response['message']=$result->getMessage();
  503 + $this->setResponse(array('status_code'=>1, 'message'=>$result->getMessage()));
  504 + return;
  505 + }
  506 +
  507 + $session=&$kt->get_session();
  508 + $download_manager=new KTDownloadManager();
  509 + $download_manager->set_session($session->session);
  510 + $download_manager->cleanup();
  511 + $url=$download_manager->allow_download($document,NULL,$multipart);
  512 + //http://ktair.dev?code=750f7a09d40a3d855f2897f417baf0bbb9a1f615&d=16&u=evm2pdkkhfagon47eh2b9slqj6
  513 + /*
  514 + $this->addDebug('url before split',$url);
  515 + $url=split('\?',$url);
  516 + $this->addDebug('url after split',$url);
  517 + $url=$url[0].'/ktwebservice/download.php?'.$url[1];
  518 + $this->addDebug('url after recombo',$url);
  519 + */
  520 +
  521 + $response['status_code']=0;
  522 + $response['message']=$url.'&apptype='.$params['app_type'];
  523 + $response['filename']=$docname;
  524 +
  525 + $this->addDebug('effective params',$params);
  526 +
  527 + if($returnResult){
  528 + return $response;
  529 + }else{
  530 + $this->setResponse($response);
  531 + }
  532 + }
  533 +
  534 + /**
  535 + * Get download URLS for multiple documents
  536 + * params contains:
  537 + * app_type
  538 + * documents = array of doc_id
  539 + *
  540 + * @param unknown_type $params
  541 + */
  542 + public function download_multiple_documents($params){
  543 + $response=array();
  544 + foreach($params['documents'] as $docId){
  545 + $ret=$this->download_document(array('document_id'=>$docId,'app_type'=>$params['app_type'],'multipart'=>$params['multipart']),true);
  546 + $rec=array(
  547 + 'filename' =>$ret['filename'],
  548 + 'url' =>$ret['message'],
  549 + 'succeeded' =>$ret['status_code']==0?true:false
  550 + );
  551 + if(is_array($ret))$response[$docId]=$rec;
  552 + }
  553 + $this->setResponse($response);
  554 + }
  555 +
  556 + /**
  557 + * Checkout a Document
  558 + * params contains:
  559 + * document_id the id of the document
  560 + * reason the checkout reason
  561 + *
  562 + * @param array $params
  563 + *
  564 + */
  565 + function checkout_document($params){
  566 + $responseType='kt_response';
  567 + $kt=&$this->KT;
  568 +
  569 + $document=&$kt->get_document_by_id($params['document_id']);
  570 + if (PEAR::isError($document))
  571 + {
  572 + $this->addError("checkout_document - cannot get documentid {$params['document_id']} - " . $document->getMessage());
  573 + $this->setResponse(array('status_code'=>1, 'message'=>$document->getMessage()));
  574 + return;
  575 + }
  576 +
  577 + $result=$document->checkout($params['reason']);
  578 + if (PEAR::isError($result))
  579 + {
  580 + $this->addError($result->getMessage());
  581 + $this->setResponse(array('status_code'=>1, 'message'=>$result->getMessage()));
  582 + return;
  583 + }
  584 +
  585 + $url='';
  586 + if ($params['download'])
  587 + {
  588 + $download_manager=new KTDownloadManager();
  589 + $download_manager->set_session($params['session_id']);
  590 + $download_manager->cleanup();
  591 + $url=$download_manager->allow_download($document);
  592 + }
  593 +
  594 + $this->setResponse(array('status_code'=>0, 'message'=>$url));
  595 + }
  596 +
  597 +
  598 + /**
  599 + * Checkin Document //TODO: Find out how upload works
  600 + * params contains:
  601 + * document_id
  602 + * filename
  603 + * reason
  604 + * tempfilename
  605 + *
  606 + * @param array $params
  607 + */
  608 + function checkin_document($params){
  609 + $session_id=$this->AuthInfo['session'];
  610 + $document_id=$params['document_id'];
  611 + $filename=$params['filename'];
  612 + $reason=$params['reason'];
  613 + $tempfilename=$params['tempfilename'];
  614 + $major_update=$params['major_update'];
  615 + $application=$this->AuthInfo['appType'];
  616 +
  617 + $this->addDebug('Checkin',"checkin_document('$session_id',$document_id,'$filename','$reason','$tempfilename', '$application', $major_update)");
  618 + $kt=&$this->KT;
  619 +
  620 + // we need to add some security to ensure that people don't frig the checkin process to access restricted files.
  621 + // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome.
  622 + $upload_manager=new KTUploadManager();
  623 + if (!$upload_manager->is_valid_temporary_file($tempfilename))
  624 + {
  625 + $this->setResponse(array('status_code'=>12));
  626 + return;
  627 + }
  628 +
  629 + $document=&$kt->get_document_by_id($document_id);
  630 + if (PEAR::isError($document))
  631 + {
  632 + $this->setResponse(array('status_code'=>13));
  633 + }
  634 +
  635 + // checkin
  636 + $result=$document->checkin($filename, $reason, $tempfilename, $major_update);
  637 + if (PEAR::isError($result))
  638 + {
  639 + $this->setResponse(array('status_code'=>14));
  640 + }
  641 +
  642 + // get status after checkin
  643 + //$this->response= $this->get_document_detail($session_id, $document_id);
  644 + $detail=$document->get_detail();
  645 + $detail['status_code']=0;
  646 + $detail['message']='';
  647 +
  648 + $this->setResponse($detail);
  649 + }
  650 +
  651 +
  652 + /**
  653 + * Upload a document
  654 + *
  655 + * @param unknown_type $arr
  656 + */
  657 + function add_document_with_metadata($arr){
  658 + $session_id=$arr['session_id'];
  659 + //error_reporting(E_ALL);
  660 + $metadata=array();
  661 + $packed=$arr['metadata'];
  662 +
  663 + foreach($meta as $item){
  664 + $fieldSet=$item['fieldset'];
  665 + unset($item['fieldset']);
  666 + $metadata[$fieldSet]['fieldset']=$fieldSet;
  667 + $metadata[$fieldSet]['fields'][]=$item;
  668 + }
  669 +
  670 + $kt=&$this->KT;
  671 +
  672 + $upload_manager=new KTUploadManager();
  673 + if (!$upload_manager->is_valid_temporary_file($arr['tempfilename'])) {
  674 + $this->addError('Temporary File Not Valid');
  675 + $this->setResponse(array('status_code'=>1, 'message'=>'Temporary File Not Valid'));
  676 + return false;
  677 + }
  678 + $this->addDebug('','Exited is_valid_temporary file');
  679 +
  680 + $folder=&$kt->get_folder_by_id($arr['folder_id']);
  681 + if (PEAR::isError($folder)){
  682 + $this->addError('Could not find Folder '.$arr['folder_id']);
  683 + $this->setResponse(array('status_code'=>1, 'message'=>'Could not find Folder '.$arr['folder_id']));
  684 + return false;
  685 + }
  686 +
  687 + $document=&$folder->add_document($arr['title'], $arr['filename'], $arr['documenttype'], $arr['tempfilename']);
  688 + if (PEAR::isError($document)){
  689 + $this->addError("Could not add Document [title:{$title},filename:{$filename},documenttype:{$documenttype},tempfilename:{$tempfilename}]");
  690 + $this->setResponse(array('status_code'=>1, 'message'=>'Could not add Document'));
  691 + return false;
  692 + }
  693 +
  694 +
  695 + $document_id=$document->get_documentid();
  696 +
  697 + $update_result=$this->update_document_metadata($arr['session_id'], $document_id, $metadata, $arr['application'], array());
  698 +
  699 + $status_code=$update_result['status_code'];
  700 + if ($status_code != 0)
  701 + {
  702 + $this->delete_document(array('session_id' => $arr['session_id'], 'document_id' => $document_id, 'reason' => 'Rollback because metadata could not be added', 'application' => $arr['application']));
  703 + $this->response= $update_result;
  704 + }
  705 +
  706 +
  707 + $result=$document->mergeWithLastMetadataVersion();
  708 + if (PEAR::isError($result))
  709 + {
  710 + // not much we can do, maybe just log!
  711 + }
  712 +
  713 + $this->response= array('status_code'=>0, 'document_id'=>$document_id);
  714 + }
  715 +
  716 + function create_empty_upload_file($params){
  717 + $config=KTConfig::getSingleton();
  718 + $this->addDebug('KTConfig Singleton',$config);
  719 + $uploadFolder=$config->get('webservice/uploadDirectory');
  720 +
  721 + $result = array();
  722 +
  723 + if ($file = fopen($uploadFolder."/".$params['filename'], 'w')) {
  724 + fclose($file);
  725 + $result['status_code'] = '0';
  726 + $result['filename'] = $uploadFolder."/".$params['filename'];
  727 + } else {
  728 + $result['status_code'] = '1';
  729 + $result['filename'] = $uploadFolder."/".$params['filename'];
  730 + }
  731 + $this->setResponse($result);
  732 + return true;
  733 + }
  734 +
  735 + function get_all_client_policies(){
  736 + $config=KTConfig::getSingleton();
  737 + $this->addDebug('KTConfig Singleton',$config);
  738 +
  739 + $policies=array('allowRememberPassword', 'captureReasonsCheckin', 'captureReasonsCheckout');
  740 +
  741 + $returnPolicies=array();
  742 +
  743 + foreach ($policies as $policy_name)
  744 + {
  745 + $policyInfo=array(
  746 + 'name'=>$policy_name,
  747 + 'value'=>serviceHelper::bool2str($config->get('addInPolicies/'.$policy_name)),
  748 + 'type'=>'boolean'
  749 + );
  750 +
  751 + $returnPolicies[$policy_name] =$policyInfo;
  752 + }
  753 +
  754 + $languages=$this->get_languages(true);
  755 +
  756 + $metadata=array('totalProperty'=>'resultsCounter', 'root'=>'languages', 'fields'=>array('isoCode', 'language'));
  757 +
  758 + $finalArray=array();
  759 + $finalArray['metaData']=$metadata;
  760 + $finalArray['policies']=$returnPolicies;
  761 + $finalArray['languages']=$languages['languages'];
  762 + $finalArray['defaultLanguage']=$languages['defaultLanguage'];
  763 + $finalArray['resultsCounter']=$languages['count'];
  764 +
  765 +
  766 + $this->setResponse($finalArray);
  767 + return true;
  768 + }
  769 +
  770 + function get_all_explorer_policies(){
  771 + $config=KTConfig::getSingleton();
  772 + $this->addDebug('KTConfig Singleton',$config);
  773 +
  774 + $policies=array('allowRememberPassword', 'explorerMetadataCapture', 'officeMetadataCapture', 'captureReasonsCheckin', 'captureReasonsCheckout', 'captureReasonsDelete', 'captureReasonsCancelCheckout', 'captureReasonsCopyInKT', 'captureReasonsMoveInKT');
  775 +
  776 + $returnPolicies=array();
  777 + $test = $config->get('clientToolPolicies/allowRememberPassword');
  778 + global $default;
  779 + $default->log->error('I am here-'.$test);
  780 + foreach ($policies as $policy_name)
  781 + {
  782 + $policyInfo=array(
  783 + 'name'=>$policy_name,
  784 + 'value'=>serviceHelper::bool2str($config->get('clientToolPolicies/'.$policy_name)),
  785 + 'type'=>'boolean'
  786 + );
  787 +
  788 + $returnPolicies[$policy_name] =$policyInfo;
  789 + }
  790 +
  791 + $languages=$this->get_languages(true);
  792 +
  793 + $metadata=array('totalProperty'=>'resultsCounter', 'root'=>'languages', 'fields'=>array('isoCode', 'language'));
  794 +
  795 + $finalArray=array();
  796 + $finalArray['metaData']=$metadata;
  797 + $finalArray['policies']=$returnPolicies;
  798 + $finalArray['languages']=$languages['languages'];
  799 + $finalArray['defaultLanguage']=$languages['defaultLanguage'];
  800 + $finalArray['resultsCounter']=$languages['count'];
  801 +
  802 +
  803 + $this->setResponse($finalArray);
  804 + return true;
  805 + }
  806 +
  807 + public function switchlang($params){
  808 + setcookie("kt_language", $params['lang'], 2147483647, '/');
  809 + }
  810 +
  811 +
  812 + function add_document_params($params){
  813 + $folder_id=$params['folder_id'];
  814 + $title=$params['title'];
  815 + $filename=$params['filename'];
  816 + $documenttype=$params['documenttype'];
  817 + $tempfilename=$params['tempfilename'];
  818 + $application=$params['application'];
  819 +
  820 + $this->addDebug('','Entered add_document');
  821 + $kt=&$this->KT;
  822 +
  823 + $upload_manager=new KTUploadManager();
  824 + if (!$upload_manager->is_valid_temporary_file($tempfilename)) {
  825 + $this->addError('Temporary File Not Valid');
  826 + $this->setResponse(array('status_code'=>1));
  827 + return false;
  828 + }
  829 + $this->addDebug('','Exited is_valid_temporary file');
  830 +
  831 + $folder=&$kt->get_folder_by_id($folder_id);
  832 + if (PEAR::isError($folder)){
  833 + $this->addError('Could not find Folder '.$folder_id);
  834 + $this->setResponse(array('status_code'=>1));
  835 + return false;
  836 + }
  837 +
  838 + $this->addDebug('','Exited get_folder_by_id');
  839 +
  840 + $document=&$folder->add_document($title, $filename, $documenttype, $tempfilename);
  841 + if (PEAR::isError($document)){
  842 + $this->addError("Could add Document [title:{$title},filename:{$filename},documenttype:{$documenttype},tempfilename:{$tempfilename}]");
  843 + $this->setResponse(array('status_code'=>1));
  844 + return false;
  845 + }
  846 +
  847 + $this->addDebug('','Exited folder add_document');
  848 +
  849 + $detail=$document->get_detail();
  850 + $detail['status_code']=0;
  851 + $detail['message']='';
  852 +
  853 + $this->setResponse($detail);
  854 + }
  855 +
  856 + function delete_document($params){
  857 + $session_id = $params['session_id'];
  858 + $document_id = $params['document_id'];
  859 + $reason = $params['reason'];
  860 + $application = $params['application'];
  861 +
  862 + $kt=&$this->KT;
  863 +
  864 + $document=&$kt->get_document_by_id($document_id);
  865 + if (PEAR::isError($document)){
  866 + $this->addError("Invalid document {$document_id}");
  867 + $this->setResponse(array('status_code'=>1));
  868 + return false;
  869 + }
  870 +
  871 + $result=$document->delete($reason);
  872 + if (PEAR::isError($result)) {
  873 + $this->addError("Could not delete document {$document_id}");
  874 + $this->setResponse(array('status_code'=>1));
  875 + return false;
  876 + }
  877 + $this->setResponse(array('status_code'=>0));
  878 + return true;
  879 + }
  880 +
  881 +
  882 +
  883 + private function update_document_metadata($session_id, $document_id, $metadata, $application, $sysdata=null){
  884 + $this->addDebug('update_document_metadata','entered update_document_metadata');
  885 + $kt=&$this->KT;
  886 + $responseType='kt_document_detail';
  887 +
  888 + $document=&$kt->get_document_by_id($document_id);
  889 + if (PEAR::isError($document)){
  890 + return array('status_code'=>1, 'error'=>'Error getting document');
  891 + }
  892 +
  893 + $result=$document->update_metadata($metadata);
  894 + if (PEAR::isError($result)){
  895 + return array('status_code'=>1, 'error'=>'Error updating metadata');
  896 + }
  897 +
  898 + $result=$document->update_sysdata($sysdata);
  899 + if (PEAR::isError($result)){
  900 + return array('status_code'=>1, 'error'=>'Error update_sysdata');
  901 + }
  902 +
  903 + return array('status_code'=>0);
  904 + }
  905 +
  906 + function get_client_policy($arr){
  907 + $policy_name=$arr['policy_name'];
  908 +
  909 + $config=KTConfig::getSingleton();
  910 +
  911 + $policy=array(
  912 + 'name'=>$policy_name,
  913 + 'value'=>serviceHelper::bool2str($config->get($policy_name)),
  914 + 'type'=>'boolean'
  915 + );
  916 +
  917 + $response['policy']=$policy;
  918 + $response['message']='Knowledgetree client policies retrieval succeeded.';
  919 + $response['status_code']=0;
  920 +
  921 + $this->setResponse($response);
  922 + return true;
  923 + }
  924 +
  925 +
  926 + function search($arr){
  927 + $kt=&$this->KT;
  928 +
  929 + $listing=processSearchExpression("(GeneralText contains \"".$arr['query']."\")");
  930 +
  931 + $result=$this->_processListing($listing, 'search', $arr);
  932 +
  933 + if(!count($result)) {
  934 + $result[]=array(
  935 + 'text'=>$this->xlate("No results found"),
  936 + 'id'=>($listing[$i]['item_type']=='F' ? $listing[$i]['item_type']."_" : "").$listing[$i]['id'],
  937 + 'leaf'=>true,
  938 + 'relevance'=>0,
  939 + 'qtip'=> $this->xlate("Please retry your search")
  940 + );
  941 + }else{
  942 + $result=array_slice($result, 0, 200);
  943 + }
  944 +
  945 + //$this->setResponse($result);
  946 + $this->setResponse(array('totalCount'=>count($listing), 'items'=>$result));
  947 +
  948 + return true;
  949 + }
  950 +
  951 +
  952 + public function update_metadata($arr){
  953 + $metadata=array();
  954 + $meta=$arr['metadata'];
  955 +
  956 + $this->addDebug('','Entered add_document_with_metadata');
  957 + $this->addDebug('metadata received',$meta);
  958 +
  959 + $special=array();
  960 +// foreach($apacked as $packed){
  961 +// foreach($packed as $key=>$val) {
  962 +// if(substr($val->name,0,2) != '__') {
  963 +// if(!is_array($metadata[$val->fieldset])) {
  964 +// $metadata[$val->fieldset]['fieldset']=$val->fieldset;
  965 +// $metadata[$val->fieldset]['fields']=array();
  966 +// }
  967 +// $metadata[$val->fieldset]['fields'][]=array(
  968 +// 'name'=>$val->name,
  969 +// 'value'=>$val->value
  970 +// );
  971 +// }else{
  972 +// $special[$val->name]=$val->value;
  973 +// }
  974 +// }
  975 +// }
  976 +
  977 + /**
  978 +
  979 +Fatal error: Cannot unset string offsets in on line 981
  980 + */
  981 +
  982 +// foreach($meta as $item){
  983 +// $isSpecial=substr($item['name'],0,2)=='__';
  984 +// if($isSpecial){
  985 +// $special[$item['name']]=$item['value'];
  986 +// }else{
  987 +// $fieldSet=$item['fieldset'];
  988 +// unset($item['fieldset']);
  989 +// $metadata[$fieldSet]['fieldset']=$fieldSet;
  990 +// $metadata[$fieldSet]['fields'][]=$item;
  991 +// }
  992 +// }
  993 +
  994 + $metadata=array();
  995 + $special=array();
  996 +
  997 + foreach($meta as $item){
  998 + if(substr($item['name'],0,2)=='__'){
  999 + $special[$item['name']]=$item['value'];
  1000 + }else{
  1001 + $metadata[$item['fieldset']]['fieldset']=$item['fieldset'];
  1002 + $metadata[$item['fieldset']]['fields'][]=array('name'=>$item['name'],'value'=>$item['value']);
  1003 + }
  1004 + }
  1005 +
  1006 +
  1007 +
  1008 + $this->addDebug('after processing',array('metadata'=>$metadata,'special'=>$special));
  1009 +
  1010 + $document_id=$arr['document_id'];
  1011 +
  1012 + $update_result=$this->update_document_metadata($arr['session_id'], $document_id, $metadata, $arr['application'], array());
  1013 + $this->addDebug('','$this->response= from update_document_metadata');
  1014 +
  1015 + $status_code=$update_result['status_code'];
  1016 + if ($status_code != 0){
  1017 + $this->setResponse($update_result);
  1018 + }
  1019 +
  1020 + $kt=&$this->KT;
  1021 +
  1022 + if(!empty($special)) {
  1023 + if($document_id > 0) {
  1024 + $document=$kt->get_document_by_id($document_id);
  1025 +
  1026 + if(isset($special['__title'])) {
  1027 + $this->addDebug("Renaming to {$special['__title']}");
  1028 + $res=$document->rename($special['__title']);
  1029 + }
  1030 + }
  1031 + }
  1032 +
  1033 + $this->setResponse(array('status_code'=>0, 'document_id'=>$document_id));
  1034 + }
  1035 +
  1036 +
  1037 +
  1038 + function check_document_title($arr){
  1039 + $kt=&$this->KT;
  1040 +
  1041 + $folder=$kt->get_folder_by_id($arr['folder_id']);
  1042 + if(PEAR::isError($folder)) {
  1043 + $this->setResponse(array('status_code'=>1, 'reason'=>'No such folder'));
  1044 + return false;
  1045 + }
  1046 +
  1047 + $doc=$folder->get_document_by_name($arr['title']);
  1048 + if(PEAR::isError($doc)) {
  1049 + $this->setResponse(array('status_code'=>1, 'reason'=>'No document with that title '.$arr['title']));
  1050 + return false;
  1051 + }
  1052 +
  1053 + $this->setResponse(array('status_code'=>0));
  1054 + return true;
  1055 + }
  1056 +
  1057 +
  1058 + function cancel_checkout($params){
  1059 + $kt=&$this->KT;
  1060 +
  1061 + $document=&$kt->get_document_by_id($params['document_id']);
  1062 + if (PEAR::isError($document)){
  1063 + $this->setResponse(array('status_code'=>1, 'message'=>$document->getMessage()));
  1064 + return false;
  1065 + }
  1066 +
  1067 + $result=$document->undo_checkout($params['reason']);
  1068 + if (PEAR::isError($result)){
  1069 + $this->setResponse(array('status_code'=>1, 'message'=>$result->getMessage()));
  1070 + return false;
  1071 + }
  1072 + $response['status_code']=0;
  1073 + $this->setResponse($response);
  1074 + }
  1075 +
  1076 +
  1077 + public function get_users_groups($params){
  1078 + $kt=&$this->KT;
  1079 + $query=$params['query'];
  1080 + //$start=$params['start'];
  1081 + //$page=$params['page'];
  1082 +
  1083 + $results=KTAPI_User::getList('name LIKE "%'.$query.'%" AND id>0');
  1084 + $returnArray=array();
  1085 + if (count($results) > 0){
  1086 + foreach ($results as $user){
  1087 + $returnArray[]=array('emailid'=>'u_'.$user->getId(), 'name'=> $user->getName(), 'to'=>preg_replace('/('.$query.')/i', '<b>${0}</b>', $user->getName()));
  1088 + }
  1089 + }
  1090 +
  1091 + $groups=KTAPI_Group::getList('name LIKE "%'.$query.'%"');
  1092 + if (count($groups) > 0){
  1093 + foreach ($groups as $group){
  1094 + $returnArray[]=array('emailid'=>'g_'.$group->getId(), 'name'=> $group->getName(), 'to'=>preg_replace('/('.$query.')/i', '<b>${0}</b>', $group->getName()));
  1095 + }
  1096 + }
  1097 +
  1098 + $sendArray=array ('emails'=>$returnArray, 'metaData'=>array('count'=>count($finalArray), 'root'=>'emails', fields=>array('name', 'to', 'emailid')));
  1099 + $this->setResponse($sendArray);
  1100 + return true;
  1101 + }
  1102 +
  1103 +
  1104 + function send_email($params){
  1105 + $kt=&$this->KT;
  1106 +
  1107 + $message=$params['message'];
  1108 + $list=$params['users'];
  1109 + $list=explode(',', $list);
  1110 +
  1111 + $recipientsList=array();
  1112 +
  1113 + foreach ($list as $recipient){
  1114 + if (trim($recipient) != ''){ // check that value is present
  1115 + // if @ sign is present, signifies email address
  1116 + if(strpos($recipient, '@') === false) {
  1117 + $recipient=trim($recipient);
  1118 + switch (substr($recipient, 0, 2)){
  1119 + case 'u_':
  1120 + $id=substr($recipient, 2);
  1121 + $user=KTAPI_User::getById($id);
  1122 + if ($user != null){
  1123 + $recipientsList[]=$user;
  1124 + }
  1125 + break;
  1126 + case 'g_':
  1127 + $id=substr($recipient, 2);
  1128 + $group=KTAPI_Group::getById($id);
  1129 + if ($group != null) {
  1130 + $recipientsList[]=$group;
  1131 + }
  1132 + break;
  1133 + }
  1134 + }else{ // Email - just add to list
  1135 + $recipientsList[]=trim($recipient);
  1136 + }
  1137 + }
  1138 + }
  1139 +
  1140 + $document=$kt->get_document_by_id($params['document']);
  1141 + if (count($recipientsList)==0) {
  1142 + $this->setResponse(array('status'=>'norecipients'));
  1143 + return false;
  1144 + }else{
  1145 + $result = $document->email($recipientsList, $message, TRUE); // true to attach document
  1146 + if (PEAR::isError($result)) {
  1147 + $this->setResponse(array('status'=>$result->getMessage()));;
  1148 + return false;
  1149 + }
  1150 + $this->setResponse(array('status'=>'documentemailed'));
  1151 + }
  1152 + return true;
  1153 + }
  1154 +
  1155 +
  1156 + function is_latest_version($params){
  1157 + $kt=&$this->KT;
  1158 +
  1159 + $documentId=$params['document_id'];
  1160 + $contentId=$params['content_id'];
  1161 +
  1162 + $result=$kt->is_latest_version($documentId, $contentId);
  1163 +
  1164 + $this->setResponse($result);
  1165 + return true;
  1166 + }
  1167 +
  1168 + function check_permission($params){
  1169 + $kt=&$this->KT;
  1170 +
  1171 + $user=$kt->get_user();
  1172 + $document=$kt->get_document_by_id($params['document_id']);
  1173 + $folder=&$kt->get_folder_by_id($document->ktapi_folder->folderid);
  1174 + $folderDetail=$folder->get_detail();
  1175 + $permissions=$folderDetail['permissions'];
  1176 + if ($user->getId()==$document->document->getCheckedOutUserID()){
  1177 + $permissions .= 'E';
  1178 + }
  1179 +
  1180 + $this->setResponse(array('status_code'=>0, 'permissions'=>$permissions));
  1181 + return true;
  1182 + }
  1183 +
  1184 + function copydocument($params){
  1185 + $kt=&$this->KT;
  1186 +
  1187 + $response=$kt->copy_document($params['documentid'], $params['destfolderid'], $params['reason']);
  1188 + if ($response['status_code']==0) {
  1189 + $this->setResponse(array('status_code'=>0, 'status'=>'itemupdated', 'icon'=>'success', 'title'=>$this->xlate('Document Copied'), 'message'=>$this->xlate('Document has been successfully copied')));
  1190 + return true;
  1191 + }else{
  1192 + $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to copy document'), 'message'=>$this->xlate('Unable to copy document')));
  1193 + return false;
  1194 + }
  1195 + }
  1196 +
  1197 + function movedocument($params){
  1198 + $kt=$this->KT;
  1199 +
  1200 + $response=$kt->move_document($params['documentid'], $params['destfolderid'], $params['reason']);
  1201 + if ($response['status_code']==0) {
  1202 + $this->setResponse(array('status_code'=>0, 'status'=>'itemupdated', 'icon'=>'success', 'title'=>$this->xlate('Document Moved'), 'message'=>$this->xlate('Document has been successfully moved')));
  1203 + return true;
  1204 + }else{
  1205 + $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to move document'), 'message'=>$this->xlate('Unable to move document')));
  1206 + return false;
  1207 + }
  1208 +
  1209 + }
  1210 +
  1211 + function copyfolder($params){
  1212 + $kt=&$this->KT;
  1213 +
  1214 + $response=$kt->copy_folder($params['sourcefolderid'], $params['destfolderid'], $params['reason']);
  1215 + if ($response['status_code']==0) {
  1216 + $this->setResponse(array('status_code'=>0, 'status'=>'itemupdated', 'icon'=>'success', 'title'=>$this->xlate('Folder Copied'), 'message'=>$this->xlate('Folder has been successfully copied')));
  1217 + return true;
  1218 + }else{
  1219 + $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to copy folder'), 'message'=>$this->xlate('Unable to copy folder')));
  1220 + return false;
  1221 + }
  1222 +
  1223 + }
  1224 +
  1225 + function movefolder($params){
  1226 + $kt=&$this->KT;
  1227 +
  1228 + $response=$kt->move_folder($params['sourcefolderid'], $params['destfolderid'], $params['reason']);
  1229 + if ($response['status_code']==0) {
  1230 + $this->setResponse(array('status_code'=>0, 'status'=>'itemupdated', 'icon'=>'success', 'title'=>$this->xlate('Folder Moved'), 'message'=>$this->xlate('Folder has been successfully moved')));
  1231 + return true;
  1232 + }else{
  1233 + $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to move folder'), 'message'=>$this->xlate('Unable to move folder')));
  1234 + return false;
  1235 + }
  1236 + }
  1237 +
  1238 +
  1239 + function renamefolder($params){
  1240 + $kt=&$this->KT;
  1241 +
  1242 + $response=$kt->rename_folder($params['currentfolderid'], $params['newname']);
  1243 + if ($response['status_code']==0) {
  1244 + $this->setResponse(array('status_code'=>0, 'status'=>'folderupdated', 'icon'=>'success', 'title'=>$this->xlate('Folder Renamed'), 'message'=>$this->xlate('Folder has been successfully renamed')));
  1245 + return true;
  1246 + }else{
  1247 + $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to rename folder'), 'message'=>$this->xlate('Unable to rename folder')));
  1248 + return false;
  1249 + }
  1250 + }
  1251 +
  1252 + function addfolder($params) {
  1253 + $kt=&$this->KT;
  1254 + $this->addDebug('parameters',$params);
  1255 + $response=$kt->create_folder($params['currentfolderid'], $params['newname']);
  1256 + $this->setResponse($response);
  1257 + return true;
  1258 + }
  1259 +
  1260 + function deletefolder($params){
  1261 + $kt=&$this->KT;
  1262 +
  1263 + $response=$kt->delete_folder($params['folderid'], $params['reason']);
  1264 + if ($response['status_code']==0) {
  1265 + $this->setResponse(array('status_code'=>0, 'status'=>'folderdeleted', 'icon'=>'success', 'title'=>$this->xlate('Folder Deleted'), 'message'=>$this->xlate('Folder has been successfully deleted')));
  1266 + return true;
  1267 + }else{
  1268 + $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to delete folder'), 'message'=>$this->xlate('Unable to delete folder')));
  1269 + return false;
  1270 + }
  1271 + }
  1272 +
  1273 + function candeletefolder($arr){
  1274 + $kt=&$this->KT;
  1275 +
  1276 + $folder=&$kt->get_folder_by_id($arr['folderid']);
  1277 + if (PEAR::isError($folder)){
  1278 + $this->setResponse('error 1');
  1279 + return false;
  1280 + }
  1281 +
  1282 + $listing=$folder->get_listing(1, 'DF');
  1283 + if (count($listing)==0) {
  1284 + $this->setResponse(array('status_code'=>0, 'candelete'=>TRUE));
  1285 + return true;
  1286 + }else{
  1287 + $this->setResponse(array('status_code'=>0, 'candelete'=>FALSE));
  1288 + return true;
  1289 + }
  1290 + }
  1291 +}
  1292 +?>
0 1293 \ No newline at end of file
... ...
webservice/clienttools/services/0.9/server.php 0 → 100644
  1 +<?php
  2 +class server extends client_service {
  3 + public function status(){
  4 + $this->setResponse(array('online'=>true));
  5 + }
  6 +
  7 + public function ping(){
  8 + $this->addResponse('pong',time());
  9 + }
  10 +
  11 + public function getToken(){
  12 +
  13 + }
  14 +
  15 + public function phpInfo(){
  16 + ob_start();
  17 + phpinfo();
  18 + $this->addResponse('phpinfo',ob_get_clean());
  19 + }
  20 +
  21 + }
  22 +?>
0 23 \ No newline at end of file
... ...