Commit 16c973ecbf73a8ab718837d5683a67acd991169e

Authored by Jarrett Jordaan
2 parents c6965373 1129b235

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

ktapi/KTAPIDocument.inc.php
@@ -2211,6 +2211,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -2211,6 +2211,7 @@ class KTAPI_Document extends KTAPI_FolderItem
2211 $version['user'] = $username; 2211 $version['user'] = $username;
2212 $version['metadata_version'] = $document->getMetadataVersion(); 2212 $version['metadata_version'] = $document->getMetadataVersion();
2213 $version['content_version'] = $document->getVersion(); 2213 $version['content_version'] = $document->getVersion();
  2214 + $version['datetime'] = $document->getVersionCreated();
2214 if ($wsversion >= 2) 2215 if ($wsversion >= 2)
2215 { 2216 {
2216 $version['metadata_version'] = (int) $version['metadata_version']; 2217 $version['metadata_version'] = (int) $version['metadata_version'];
lib/documentmanagement/documentutil.inc.php 100644 → 100755
@@ -581,9 +581,100 @@ $sourceDocument->getName(), @@ -581,9 +581,100 @@ $sourceDocument->getName(),
581 } 581 }
582 // }}} 582 // }}}
583 583
  584 + /*
  585 + * Function to sanitize the date input from any textual date representation to a valid KT date format
  586 + * - Will check for any string supported by strtotime which can be any US English date format.
  587 + * - Further corrects any quote descrepancies and checks the textual description again.
  588 + * - If still no valid date then takes the integers and separators to produce a best guess.
  589 + */
  590 + function sanitizeDate($sDate) {
  591 +
  592 + //Checking for Normal Strings, e.g. 13 August 2009 etc. All formats accepted by strtotime()
  593 + $datetime = date_create($sDate);
  594 + $resDate = date_format($datetime, 'Y-m-d');
  595 +
  596 + if (!trim($resDate) == '') {
  597 + return $resDate;
  598 + } else {
  599 + //If null then removing quotes e.g. 14'th doesn't yield a valid date but 14th does
  600 + $sDate = str_replace("'", '', $sDate);
  601 + $sDate = str_replace('"', '', $sDate);
  602 +
  603 + $datetime = date_create($sDate);
  604 + $resDate = date_format($datetime, 'Y-m-d');
  605 +
  606 + if (!trim($resDate) == '') {
  607 + return $resDate;
  608 + } else {
  609 + //If null then trying with numeric data
  610 + //Stripping non-numerics
  611 + $sDate = preg_replace('/[^0-9]/', '-', $sDate);
  612 + $token = strpos($sDate, '--');
  613 +
  614 + while ($token != 0)
  615 + {
  616 + $sDate = str_replace('--', '-', $sDate);
  617 + $token = strpos($sDate, '--');
  618 + }
  619 +
  620 + $datetime = date_create($sDate);
  621 + $resDate = date_format($datetime, 'Y-m-d');
  622 +
  623 + return $resDate;
  624 +
  625 + }
  626 + }
  627 + }
  628 +
  629 + // Forcefully sanitize metadata, specifically date values, to account for client tools that submit unvalidated date input
  630 + // Will produce a best effort match to a valid date format.
  631 + function sanitizeMetadata($oDocument, $aMetadata){
  632 + $aFieldsets =& KTFieldset::getGenericFieldsets();
  633 + $aFieldsets =& kt_array_merge($aFieldsets,
  634 + KTFieldset::getForDocumentType($oDocument->getDocumentTypeId()));
  635 + $aSimpleMetadata = array();
  636 + foreach ($aMetadata as $aSingleMetadatum) {
  637 + list($oField, $sValue) = $aSingleMetadatum;
  638 + if (is_null($oField)) {
  639 + continue;
  640 + }
  641 + $aSimpleMetadata[$oField->getId()] = $sValue;
  642 + }
  643 +
  644 + foreach ($aFieldsets as $oFieldset) {
  645 + $aFields =& $oFieldset->getFields();
  646 + $aFieldValues = array();
  647 + foreach ($aFields as $oField) {
  648 + $val = KTUtil::arrayGet($aSimpleMetadata, $oField->getId());
  649 + if (!empty($v)) {
  650 + $aFieldValues[$oField->getId()] = $val;
  651 + }
  652 +
  653 + //Sanitizing Date Values
  654 + if ($oField->getDataType() == 'DATE') {
  655 + $val = KTDocumentUtil::sanitizeDate($val);
  656 + }
  657 +
  658 + if (!is_null($val)) {
  659 + $MDPack[] = array(
  660 + $oField,
  661 + $val
  662 + );
  663 + }
  664 +
  665 + }
  666 + }
  667 +
  668 + return $MDPack;
  669 + }
  670 +
584 // {{{ saveMetadata 671 // {{{ saveMetadata
585 function saveMetadata(&$oDocument, $aMetadata, $aOptions = null) { 672 function saveMetadata(&$oDocument, $aMetadata, $aOptions = null) {
586 $table = 'document_fields_link'; 673 $table = 'document_fields_link';
  674 +
  675 + //Sanitizing Date Fields
  676 + $aMetadata = KTDocumentUtil::sanitizeMetadata($oDocument, $aMetadata);
  677 +
587 $bNoValidate = KTUtil::arrayGet($aOptions, 'novalidate', false); 678 $bNoValidate = KTUtil::arrayGet($aOptions, 'novalidate', false);
588 if ($bNoValidate !== true) 679 if ($bNoValidate !== true)
589 { 680 {
sql/mysql/install/data.sql
@@ -162,7 +162,8 @@ INSERT INTO `config_groups` VALUES @@ -162,7 +162,8 @@ INSERT INTO `config_groups` VALUES
162 (21, 'user_prefs', 'User Preferences', 'Configures user preferences.', 'General Settings'), 162 (21, 'user_prefs', 'User Preferences', 'Configures user preferences.', 'General Settings'),
163 (22, 'webservice', 'Web Services', 'KnowledgeTree Web Service Interface configuration. Note that a number of KnowledgeTree Tools rely on this service.', 'Client Tools Settings'), 163 (22, 'webservice', 'Web Services', 'KnowledgeTree Web Service Interface configuration. Note that a number of KnowledgeTree Tools rely on this service.', 'Client Tools Settings'),
164 (23, 'ldapAuthentication', 'LDAP Authentication', 'Configures LDAP Authentication', 'General Settings'), 164 (23, 'ldapAuthentication', 'LDAP Authentication', 'Configures LDAP Authentication', 'General Settings'),
165 -(24, 'server', 'Server Settings', 'Configuration settings for the server', 'General Settings'); 165 +(24, 'server', 'Server Settings', 'Configuration settings for the server', 'General Settings'),
  166 +(25, 'explorerCPSettings', 'Explorer CP Settings', 'Configuration options for KnowledgeTree Explorer CP', 'Client Tools Settings');
166 /*!40000 ALTER TABLE `config_groups` ENABLE KEYS */; 167 /*!40000 ALTER TABLE `config_groups` ENABLE KEYS */;
167 UNLOCK TABLES; 168 UNLOCK TABLES;
168 169
@@ -291,7 +292,8 @@ INSERT INTO `config_settings` VALUES @@ -291,7 +292,8 @@ INSERT INTO `config_settings` VALUES
291 (116, 'export', 'Use External Zip Binary', 'Utilises the external zip binary for compressing archives. The default is to use the PEAR archive class.', 'useBinary', 'default', 'true', 'boolean', NULL, 0), 292 (116, 'export', 'Use External Zip Binary', 'Utilises the external zip binary for compressing archives. The default is to use the PEAR archive class.', 'useBinary', 'default', 'true', 'boolean', NULL, 0),
292 (117, 'export', 'Use Bulk Download Queue', 'The bulk download can be large and can prevent normal browsing. The download queue performs the bulk downloads in the background.', 'useDownloadQueue', 'default', 'true', 'boolean', NULL, 1), 293 (117, 'export', 'Use Bulk Download Queue', 'The bulk download can be large and can prevent normal browsing. The download queue performs the bulk downloads in the background.', 'useDownloadQueue', 'default', 'true', 'boolean', NULL, 1),
293 (118, 'urls', 'Internal Var Directory', 'The path to the internal var directory that must sit within the web root', 'internalVarDirectory', 'default', '${fileSystemRoot}/var', 'string', NULL, 0), 294 (118, 'urls', 'Internal Var Directory', 'The path to the internal var directory that must sit within the web root', 'internalVarDirectory', 'default', '${fileSystemRoot}/var', 'string', NULL, 0),
294 -(119, 'externalBinary', 'convert', 'The path to the ImageMagick "convert" binary', 'convertPath', 'default', 'convert', 'string', NULL, 1); 295 +(119, 'externalBinary', 'convert', 'The path to the ImageMagick "convert" binary', 'convertPath', 'default', 'convert', 'string', NULL, 1),
  296 +(120, 'explorerCPSettings', 'Debug Log Level', 'Set the level of debug information included in the server side log file', 'debugLevel', 'error', 'error', 'dropdown', 'a:1:{s:7:\"options\";a:3:{i:0;a:2:{s:5:\"value\";s:3:\"off\";s:5:\"label\";s:10:\"No Logging\";}i:1;a:2:{s:5:\"value\";s:5:\"error\";s:5:\"label\";s:18:\"Error Logging Only\";}i:2;a:2:{s:5:\"value\";s:5:\"debug\";s:5:\"label\";s:28:\"Error and Debug Info Logging\";}}}', 1);
295 /*!40000 ALTER TABLE `config_settings` ENABLE KEYS */; 297 /*!40000 ALTER TABLE `config_settings` ENABLE KEYS */;
296 UNLOCK TABLES; 298 UNLOCK TABLES;
297 299
@@ -1775,7 +1777,8 @@ INSERT INTO `upgrades` VALUES @@ -1775,7 +1777,8 @@ INSERT INTO `upgrades` VALUES
1775 (231,'sql*3.7.0.1*0*3.7.0.1/mime_extractors_reset.sql','Database upgrade to version 3.7.0.1: Mime extractors reset','2009-09-01 00:00:00',1,'upgrade*3.7.0.1*99*upgrade3.7.0.1'), 1777 (231,'sql*3.7.0.1*0*3.7.0.1/mime_extractors_reset.sql','Database upgrade to version 3.7.0.1: Mime extractors reset','2009-09-01 00:00:00',1,'upgrade*3.7.0.1*99*upgrade3.7.0.1'),
1776 (232,'upgrade*3.7.0.1*99*upgrade3.7.0.1','Upgrade from version 3.6.3 to 3.7.0.1','2009-11-13 00:00:00',1,'upgrade*3.7.0.1*99*upgrade3.7.0.1'), 1778 (232,'upgrade*3.7.0.1*99*upgrade3.7.0.1','Upgrade from version 3.6.3 to 3.7.0.1','2009-11-13 00:00:00',1,'upgrade*3.7.0.1*99*upgrade3.7.0.1'),
1777 (233,'sql*3.7.0.2*0*3.7.0.2/processor_queue.sql','Database upgrade to version 3.7.0.1: Processor Queue','2009-09-01 00:00:00',1,'upgrade*3.7.0.2*99*upgrade3.7.0.2'), 1779 (233,'sql*3.7.0.2*0*3.7.0.2/processor_queue.sql','Database upgrade to version 3.7.0.1: Processor Queue','2009-09-01 00:00:00',1,'upgrade*3.7.0.2*99*upgrade3.7.0.2'),
1778 -(234,'upgrade*3.7.0.2*99*upgrade3.7.0.2','Upgrade from version 3.7.0.1 to 3.7.0.2','2009-11-19 00:00:00',1,'upgrade*3.7.0.2*99*upgrade3.7.0.2'); 1780 +(234,'upgrade*3.7.0.2*99*upgrade3.7.0.2','Upgrade from version 3.7.0.1 to 3.7.0.2','2009-11-19 00:00:00',1,'upgrade*3.7.0.2*99*upgrade3.7.0.2'),
  1781 +(233,'sql*3.7.0.3*0*3.7.0.3/clienttools_config.sql','Database upgrade to version 3.7.0.3: Clienttools Config','2009-12-10 00:00:00',1,'upgrade*3.7.0.3*99*upgrade3.7.0.3');
1779 /*!40000 ALTER TABLE `upgrades` ENABLE KEYS */; 1782 /*!40000 ALTER TABLE `upgrades` ENABLE KEYS */;
1780 UNLOCK TABLES; 1783 UNLOCK TABLES;
1781 1784
sql/mysql/upgrade/3.7.0.3/data.sql renamed to sql/mysql/upgrade/3.7.0.3/clienttools_config.sql
webservice/clienttools/ajaxhandler.php
@@ -37,6 +37,7 @@ class ajaxHandler{ @@ -37,6 +37,7 @@ class ajaxHandler{
37 }else{ 37 }else{
38 $this->ret=new jsonResponseObject(); 38 $this->ret=new jsonResponseObject();
39 } 39 }
  40 + $this->ret->location='ajaxhandler';
40 $this->log("[__construct]ENTERING PREPARATIONS"); 41 $this->log("[__construct]ENTERING PREPARATIONS");
41 42
42 $this->remoteIp = (getenv(HTTP_X_FORWARDED_FOR)) ? getenv(HTTP_X_FORWARDED_FOR) : getenv(REMOTE_ADDR); 43 $this->remoteIp = (getenv(HTTP_X_FORWARDED_FOR)) ? getenv(HTTP_X_FORWARDED_FOR) : getenv(REMOTE_ADDR);
webservice/clienttools/client_service.php
@@ -20,6 +20,8 @@ class client_service{ @@ -20,6 +20,8 @@ class client_service{
20 $this->KT=&$KT_Instance; 20 $this->KT=&$KT_Instance;
21 $this->AuthInfo=&$AuthInfo; 21 $this->AuthInfo=&$AuthInfo;
22 $this->Request=&$Request; 22 $this->Request=&$Request;
  23 +
  24 + $this->Response->location='client service';
23 } 25 }
24 26
25 protected function addResponse($name,$value){ 27 protected function addResponse($name,$value){
@@ -42,6 +44,18 @@ class client_service{ @@ -42,6 +44,18 @@ class client_service{
42 return $var; 44 return $var;
43 } 45 }
44 46
  47 + protected function logTrace($location=NULL,$message=NULL){
  48 + Clienttools_Syslog::logTrace($this->AuthInfo['user'],'SERVICE - '.$location,$message);
  49 + }
  50 +
  51 + protected function logError($location=NULL,$detail=NULL,$err=NULL){
  52 + Clienttools_Syslog::logError($this->AuthInfo['user'],'SERVICE - '.$location,$detail,$err);
  53 + }
  54 +
  55 + protected function logInfo($location=NULL,$message=NULL,$debugData=NULL){
  56 + Clienttools_Syslog::logInfo($this->AuthInfo['user'],'SERVICE - '.$location,$message,$debugData);
  57 + }
  58 +
45 protected function checkPearError($obj,$errMsg,$debug=NULL,$response=NULL){ 59 protected function checkPearError($obj,$errMsg,$debug=NULL,$response=NULL){
46 if (PEAR::isError($obj)){ 60 if (PEAR::isError($obj)){
47 if($response===NULL)$response=array('status_code' => 1); 61 if($response===NULL)$response=array('status_code' => 1);
webservice/clienttools/clienttools_syslog.php
1 <?php 1 <?php
2 - 2 +class Clienttools_Syslog{
  3 + /** The default folder in which to put the log files **/
  4 + private static $logFolder='../../var/log/';
  5 + private static $debugLogTemplate='[date] | [time] | INFO | [session] | [user] | [location] | [debug_message] | ([debug_data])';
  6 + private static $traceLogTemplate='[date] | [time] | LOG | [session] | [user] | [location] | [trace_message]';
  7 + private static $errorLogTemplate='[date] | [time] | ERROR | [session] | [user] | [location] | [error_detail] | ([error])';
  8 +
  9 +
  10 + private static function parseTemplate($template=NULL,$data=NULL){
  11 + $ret=null;
  12 + if(is_array($data)){
  13 + $txs=array_keys($data);
  14 + foreach($txs as $idx=>$val){
  15 + $txs[$idx]='['.$val.']';
  16 + }
  17 + $txd=array_values($data);
  18 + $ret=str_replace($txs,$txd,$template);
  19 + };
  20 +// echo print_r(Array('s'=>$txs,'d'=>$txd),true)."\n\n\n\n\n\n";
  21 + return $ret;
  22 + }
  23 +
  24 +
  25 + /**
  26 + * Return the calculated log file name
  27 + * @return void
  28 + */
  29 + private static function getLogFile(){
  30 + $fileName=self::$logFolder.'kt_clienttools_'.date('Y-m-d').'.log.txt';
  31 + return $fileName;
  32 + }
  33 +
  34 +
  35 + private static function writeLogLine($line=NULL){
  36 +// echo('LOGFILE: '.realpath(self::getLogFile()));
  37 + if($line){
  38 + $fp=fopen(self::getLogFile(),'a');
  39 + fwrite($fp,$line."\n");
  40 + fclose($fp);
  41 + }
  42 + }
  43 +
  44 + /**
  45 + * Return a boolean indicating whether error logging should be done
  46 + * @return boolean
  47 + */
  48 + private static function doErrorLogging(){
  49 +// $GLOBALS['default']['debugLevel']; //Another less secure way of finding the configured debugLevel
  50 + return KTConfig::getSingleton()->get('explorerCPSettings/debugLevel')=='error' || self::doDebugLogging();
  51 + }
  52 +
  53 + /**
  54 + * Return a boolean indicating whether debug logging should be done
  55 + * @return boolean
  56 + */
  57 + private static function doDebugLogging(){
  58 + return KTConfig::getSingleton()->get('explorerCPSettings/debugLevel')=='debug';
  59 + }
  60 +
  61 + public static function logInfo($user,$location,$message,$data){
  62 + list($usec, $sec) = explode(" ", microtime());
  63 + $usec=ceil($usec*1000);
  64 + $entry=self::parseTemplate(self::$debugLogTemplate,array(
  65 + 'date' =>date('Y-m-d'),
  66 + 'time' =>date('h:i:s').':'.$usec,
  67 + 'user' =>$user,
  68 + 'session'=>session_id(),
  69 + 'location'=>$location,
  70 + 'debug_message'=>$message,
  71 + 'debug_data'=>json_encode($data)
  72 + ));
  73 +
  74 + self::writeLogLine($entry);
  75 + }
  76 +
  77 + public static function logTrace($user,$location,$message){
  78 + list($usec, $sec) = explode(" ", microtime());
  79 + $usec=ceil($usec*1000);
  80 + $entry=self::parseTemplate(self::$traceLogTemplate,array(
  81 + 'date' =>date('Y-m-d'),
  82 + 'time' =>date('h:i:s').':'.$usec,
  83 + 'user' =>$user,
  84 + 'session'=>session_id(),
  85 + 'location'=>$location,
  86 + 'trace_message'=>$message,
  87 + ));
  88 +
  89 + self::writeLogLine($entry);
  90 + }
  91 +
  92 + public static function logError($user=NULL,$location=NULL,$detail=NULL,$err=NULL){
  93 + list($usec, $sec) = explode(" ", microtime());
  94 + $usec=ceil($usec*1000);
  95 + $entry=self::parseTemplate(self::$errorLogTemplate,array(
  96 + 'date' =>date('Y-m-d'),
  97 + 'time' =>date('h:i:s').':'.$usec,
  98 + 'user' =>$user,
  99 + 'session'=>session_id(),
  100 + 'location'=>$location,
  101 + 'error_detail'=>json_encode($detail),
  102 + 'error'=>json_encode($err),
  103 + ));
  104 +
  105 + self::writeLogLine($entry);
  106 +
  107 + }
  108 +}
3 ?> 109 ?>
4 \ No newline at end of file 110 \ No newline at end of file
webservice/clienttools/comms.php
@@ -15,10 +15,27 @@ define(&#39;COMMS_DEBUG&#39;,true); @@ -15,10 +15,27 @@ define(&#39;COMMS_DEBUG&#39;,true);
15 * 15 *
16 * return json Error Response 16 * return json Error Response
17 */ 17 */
18 -function error_handler($e,$errstr=null,$errfile=null,$errline=null){ 18 +function error_handler($errno,$errstr=null,$errfile=null,$errline=null){
  19 + $e=new ErrorException($errstr,0,$errno,$errfile,$errline);
  20 + print_r($e);
19 if($GLOBALS['RET']){ 21 if($GLOBALS['RET']){
20 - $GLOBALS['RET']->addError($errfile?$errstr:$e->getmessage());  
21 - $GLOBALS['RET']->setDebug($errfile?'ERR':'EXC',$errfile?(array('error_number'=>$e,'error_string'=>$errstr,'error_file'=>$errfile,'error_line'=>$errline)):$e); 22 + $GLOBALS['RET']->addError($e->getmessage());
  23 + $GLOBALS['RET']->setDebug('Exception::',$e);
  24 + echo $GLOBALS['RET']->getJson();
  25 + exit;
  26 + };
  27 +// if($GLOBALS['RET']){
  28 +// $GLOBALS['RET']->addError($errfile?$errstr:$e->getmessage());
  29 +// $GLOBALS['RET']->setDebug($errfile?'ERR':'EXC',$errfile?(array('error_number'=>$e,'error_string'=>$errstr,'error_file'=>$errfile,'error_line'=>$errline)):$e);
  30 +// echo $GLOBALS['RET']->getJson();
  31 +// exit;
  32 +// };
  33 +}
  34 +
  35 +function exception_handler($e){
  36 + if($GLOBALS['RET']){
  37 + $GLOBALS['RET']->addError($e->getmessage());
  38 + $GLOBALS['RET']->setDebug('Exception::',$e);
22 echo $GLOBALS['RET']->getJson(); 39 echo $GLOBALS['RET']->getJson();
23 exit; 40 exit;
24 }; 41 };
@@ -27,8 +44,8 @@ function error_handler($e,$errstr=null,$errfile=null,$errline=null){ @@ -27,8 +44,8 @@ function error_handler($e,$errstr=null,$errfile=null,$errline=null){
27 /** 44 /**
28 * Set the error & exception handlers 45 * Set the error & exception handlers
29 */ 46 */
30 -$old_exception_handler=set_exception_handler('error_handler');  
31 $old_error_handler=set_error_handler('error_handler',E_ERROR); 47 $old_error_handler=set_error_handler('error_handler',E_ERROR);
  48 +$old_exception_handler=set_exception_handler('exception_handler');
32 49
33 50
34 51
@@ -42,6 +59,7 @@ include_once(&#39;jsonWrapper.php&#39;); @@ -42,6 +59,7 @@ include_once(&#39;jsonWrapper.php&#39;);
42 include_once('ajaxhandler.php'); 59 include_once('ajaxhandler.php');
43 include_once('serviceHelper.php'); 60 include_once('serviceHelper.php');
44 include_once('client_service.php'); 61 include_once('client_service.php');
  62 +include_once('clienttools_syslog.php');
45 63
46 //Instantiate base classes 64 //Instantiate base classes
47 $KT = new KTAPI(); 65 $KT = new KTAPI();
@@ -74,6 +92,6 @@ $handler=new ajaxHandler($RET,$KT,$noAuthRequests); @@ -74,6 +92,6 @@ $handler=new ajaxHandler($RET,$KT,$noAuthRequests);
74 /** 92 /**
75 * Reset the error & exception handlers 93 * Reset the error & exception handlers
76 */ 94 */
77 -set_exception_handler($old_exception_handler);  
78 -set_error_handler($old_error_handler,E_ALL); 95 +//set_exception_handler($old_exception_handler);
  96 +//set_error_handler($old_error_handler,E_ALL);
79 ?> 97 ?>
80 \ No newline at end of file 98 \ No newline at end of file
webservice/clienttools/jsonWrapper.php
@@ -14,6 +14,7 @@ class jsonResponseObject{ @@ -14,6 +14,7 @@ class jsonResponseObject{
14 protected $debug=array(); 14 protected $debug=array();
15 public $additional=array(); 15 public $additional=array();
16 public $isDataSource=false; 16 public $isDataSource=false;
  17 + public $location='';
17 18
18 public $includeDebug=true; 19 public $includeDebug=true;
19 20
@@ -36,6 +37,8 @@ class jsonResponseObject{ @@ -36,6 +37,8 @@ class jsonResponseObject{
36 37
37 public function addError($message=NULL,$code=NULL){ 38 public function addError($message=NULL,$code=NULL){
38 $this->errors[]=array('code'=>$code,'message'=>$message); 39 $this->errors[]=array('code'=>$code,'message'=>$message);
  40 + $user=isset($this->request['auth']['user'])?$this->request['auth']['user']:'';
  41 + Clienttools_Syslog::logError($user,$this->location,array('code'=>$code,'message'=>$message),'');
39 } 42 }
40 43
41 public function setStatus($varName=NULL,$value=NULL){ 44 public function setStatus($varName=NULL,$value=NULL){
@@ -53,6 +56,8 @@ class jsonResponseObject{ @@ -53,6 +56,8 @@ class jsonResponseObject{
53 public function setDebug($varName=NULL,$value=NULL){ 56 public function setDebug($varName=NULL,$value=NULL){
54 if(is_array($this->debug[$varName]) && is_array($value))$value=array_merge($this->debug[$varName],$value); 57 if(is_array($this->debug[$varName]) && is_array($value))$value=array_merge($this->debug[$varName],$value);
55 $this->debug[$varName]=$value; 58 $this->debug[$varName]=$value;
  59 + $user=isset($this->request['auth']['user'])?$this->request['auth']['user']:'';
  60 + Clienttools_Syslog::logInfo($user,$this->location,$varName,$value);
56 } 61 }
57 62
58 public function addDebug($varName=NULL,$value=NULL){$this->setDebug($varName,$value);} 63 public function addDebug($varName=NULL,$value=NULL){$this->setDebug($varName,$value);}
@@ -68,6 +73,8 @@ class jsonResponseObject{ @@ -68,6 +73,8 @@ class jsonResponseObject{
68 73
69 public function log($str){ 74 public function log($str){
70 $this->log[]='['.date('h:i:s').'] '.$str; 75 $this->log[]='['.date('h:i:s').'] '.$str;
  76 + $user=isset($this->request['auth']['user'])?$this->request['auth']['user']:'';
  77 + Clienttools_Syslog::logTrace($user,$this->location,$str);
71 } 78 }
72 79
73 public function getJson(){ 80 public function getJson(){
webservice/clienttools/services/0.9/auth.php
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 class auth extends client_service { 3 class auth extends client_service {
4 4
5 public function login(){ 5 public function login(){
  6 + $this->logTrace((__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
6 $params=$this->AuthInfo; 7 $params=$this->AuthInfo;
7 8
8 $username=$params['user']; 9 $username=$params['user'];
@@ -71,6 +72,7 @@ class auth extends client_service { @@ -71,6 +72,7 @@ class auth extends client_service {
71 } 72 }
72 73
73 public function japiLogin(){ 74 public function japiLogin(){
  75 + $this->logTrace((__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
74 global $default; 76 global $default;
75 77
76 $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']); 78 $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']);
@@ -82,6 +84,7 @@ class auth extends client_service { @@ -82,6 +84,7 @@ class auth extends client_service {
82 } 84 }
83 85
84 public function pickup_session(){ 86 public function pickup_session(){
  87 + $this->logTrace((__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
85 $params=$this->AuthInfo; 88 $params=$this->AuthInfo;
86 $app_type=$params['appType']; 89 $app_type=$params['appType'];
87 $session_id=$params['session']; 90 $session_id=$params['session'];
@@ -98,6 +101,7 @@ class auth extends client_service { @@ -98,6 +101,7 @@ class auth extends client_service {
98 101
99 102
100 public function ping(){ 103 public function ping(){
  104 + $this->logTrace((__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
101 global $default; 105 global $default;
102 $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']); 106 $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']);
103 $versions=$this->handler->getServerVersions(); 107 $versions=$this->handler->getServerVersions();
@@ -120,12 +124,19 @@ class auth extends client_service { @@ -120,12 +124,19 @@ class auth extends client_service {
120 } 124 }
121 125
122 function logout($params){ 126 function logout($params){
  127 + $this->logTrace((__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
123 $params=$this->AuthInfo; 128 $params=$this->AuthInfo;
124 $app_type=$params['appType']; 129 $app_type=$params['appType'];
125 $session_id=$params['session']; 130 $session_id=$params['session'];
126 $ip=$_SERVER['REMOTE_ADDR']; 131 $ip=$_SERVER['REMOTE_ADDR'];
127 132
128 - $session = $this->KT->get_active_session($session_id, $ip, $app_type); 133 + $session=$this->KT->get_session();
  134 + $this->logInfo((__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Logout Session Object (From KT)',$session);
  135 +
  136 + if(get_class($session)!='KTAPI_UserSession'){
  137 + $session = $this->KT->get_active_session($session_id, $ip, $app_type);
  138 + }
  139 + $this->logInfo((__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Logout Session Object (To Logout)',$session);
129 140
130 if (PEAR::isError($session)){ 141 if (PEAR::isError($session)){
131 return false; 142 return false;
webservice/clienttools/services/0.9/kt.php
1 <?php 1 <?php
2 -class kt extends client_service {  
3 -  
4 - 2 +class kt extends client_service {
5 3
6 -/**  
7 - * Get Supported (?) Languages  
8 - *  
9 - * returns array containing languages, count, & defaultlanguage  
10 - *  
11 - */  
12 - function get_languages($passthru=false){ 4 + /**
  5 + * Get Supported (?) Languages
  6 + *
  7 + * returns array containing languages, count, & defaultlanguage
  8 + *
  9 + */
  10 + function get_languages($passthru = false) {
  11 + $this->logTrace ( __CLASS__ . '::' . __METHOD__ . '(' . __FILE__ . ' ' . __LINE__, 'Enter Function' );
13 global $default; 12 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 - ); 13 + $oReg = & KTi18nregistry::getSingleton ();
  14 + $aRegisteredLangs = $oReg->geti18nLanguages ( 'knowledgeTree' );
  15 + $aLanguageNames = $oReg->getLanguages ( 'knowledgeTree' );
  16 + $languages = array ();
  17 +
  18 + if (! empty ( $aRegisteredLangs )) {
  19 + foreach ( array_keys ( $aRegisteredLangs ) as $sLang ) {
  20 + $languages [] = array ('isoCode' => $sLang, 'language' => $aLanguageNames [$sLang] );
25 } 21 }
26 } 22 }
27 - $response=array('languages'=>$languages, 'count'=>count($languages), 'defaultLanguage'=>$default->defaultLanguage);  
28 - if(is_bool($passthru))if($passthru)return $response;  
29 - $this->setResponse($response); 23 + $response = array ('languages' => $languages, 'count' => count ( $languages ), 'defaultLanguage' => $default->defaultLanguage );
  24 + if (is_bool ( $passthru ))
  25 + if ($passthru)
  26 + return $response;
  27 + $this->setResponse ( $response );
30 } 28 }
31 -  
32 -  
33 - function get_rootfolder_detail($params){  
34 - $params['folderId']='1';  
35 - $this->get_folder_detail($params); 29 +
  30 + function get_rootfolder_detail($params) {
  31 + $this->logTrace ( __CLASS__ . '::' . __METHOD__ . '(' . __FILE__ . ' ' . __LINE__, 'Enter Function' );
  32 + $params ['folderId'] = '1';
  33 + $this->get_folder_detail ( $params );
36 } 34 }
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]; 35 +
  36 + function get_folder_detail($params) {
  37 + $this->logTrace ( __CLASS__ . '::' . __METHOD__ . '(' . __FILE__ . ' ' . __LINE__, 'Enter Function' );
  38 + if (isset ( $params ['node'] ) && ! isset ( $params ['folderId'] )) {
  39 + $params ['node'] = split ( '_', $params ['node'] );
  40 + $params ['folderId'] = $params ['node'] [1];
43 } 41 }
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)); 42 + $kt = &$this->KT;
  43 +
  44 + $folder = &$kt->get_folder_by_id ( $params ['folderId'] );
  45 + if (PEAR::isError ( $folder )) {
  46 + $this->setError ( "Could not get folder by Id: {$params['folderId']}" );
  47 + $this->setDebug ( 'FolderError', array ('kt' => $kt, 'folder' => $folder ) );
51 return false; 48 return false;
52 } 49 }
53 -  
54 - $detail=$folder->get_detail();  
55 - if (PEAR::isError($detail)){  
56 - $this->setResponse("detail error {$params['node']}"); 50 +
  51 + $detail = $folder->get_detail ();
  52 + if (PEAR::isError ( $detail )) {
  53 + $this->setResponse ( "detail error {$params['node']}" );
57 return false; 54 return false;
58 } 55 }
59 -  
60 - if(strtolower($detail['folder_name'])=='root folder'){  
61 - $detail['folder_name']='KnowledgeTree'; 56 +
  57 + if (strtolower ( $detail ['folder_name'] ) == 'root folder') {
  58 + $detail ['folder_name'] = 'KnowledgeTree';
62 } 59 }
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; 60 +
  61 + $qtip .= $this->xlate ( 'Folder name' ) . ": {$detail['folder_name']}<br>";
  62 + $class = 'folder';
  63 +
  64 + $permissions = $detail ['permissions'];
  65 + $perms = '';
  66 + $canWrite = false;
  67 +
  68 + for($j = 0; $j < strlen ( $permissions ); $j ++) {
  69 + switch (strtoupper ( $permissions {$j} )) {
  70 + case 'W' :
  71 + $canWrite = true;
  72 + $perms .= $this->xlate ( 'write, ' );
  73 + break;
  74 + case 'R' :
  75 + $perms .= $this->xlate ( 'read, ' );
  76 + break;
  77 + case 'A' :
  78 + $perms .= $this->xlate ( 'add folder, ' );
  79 + break;
83 } 80 }
84 } 81 }
85 -  
86 - if (strlen($perms) > 2){  
87 - $perms=substr($perms, 0, strlen($perms)-2); 82 +
  83 + if (strlen ( $perms ) > 2) {
  84 + $perms = substr ( $perms, 0, strlen ( $perms ) - 2 );
88 } 85 }
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); 86 +
  87 + $qtip .= $this->xlate ( 'Permissions:' ) . " {$perms}<br>";
  88 + $qtip .= $canWrite ? $this->xlate ( 'You may add content to this folder' ) : $this->xlate ( 'You may not add content to this folder' );
  89 +
  90 + $result [] = array ('text' => $detail ['folder_name'], 'id' => 'F_' . $params ['folderId'], 'filename' => $detail ['folder_name'], 'cls' => 'folder', 'leaf' => false, 'document_type' => '', 'item_type' => 'F', 'permissions' => $permissions, 'qtip' => $qtip );
  91 +
  92 + $this->setResponse ( $result );
106 return true; 93 return true;
107 } 94 }
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; 95 +
  96 + function get_folder_contents($params) {
  97 + $this->logTrace ( __CLASS__ . '::' . __METHOD__ . '(' . __FILE__ . ' ' . __LINE__, 'Enter Function' );
  98 + $kt = &$this->KT;
  99 +
  100 + $params ['control'] = 'F_';
  101 + $params ['node'] = substr ( $params ['node'], strlen ( $params ['control'] ) );
  102 +
  103 + $folder = &$kt->get_folder_by_id ( $params ['node'] );
  104 + if (! $this->checkPearError ( $folder, "[error 1] Folder Not Found: {$params['control']}{$params['node']}", '', array () ))
  105 + return false;
  106 +
  107 + $types = (isset ( $params ['types'] ) ? $params ['types'] : 'DF');
  108 + $listing = $folder->get_listing ( 1, $types );
  109 + $result = $this->_processListing ( $listing, 'folderContents', $params );
  110 +
  111 + $this->setResponse ( $result );
  112 + return true;
125 } 113 }
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'); 114 +
  115 + /**
  116 + * Returns the contents of a folder formatted for a grid view.
  117 + *
  118 + * @param array $arr
  119 + * @return array
  120 + */
  121 + function get_folder_contents_for_grid($arr) {
  122 + $this->logTrace ( __CLASS__ . '::' . __METHOD__ . '(' . __FILE__ . ' ' . __LINE__, 'Enter Function' );
  123 + $kt = &$this->KT;
  124 +
  125 + $arr ['control'] = 'F_';
  126 + $arr ['node'] = substr ( $arr ['node'], strlen ( $arr ['control'] ) );
  127 +
  128 + $folder = &$kt->get_folder_by_id ( $arr ['node'] );
  129 + if (PEAR::isError ( $folder )) {
  130 + echo '<pre>' . print_r ( $arr, true ) . '</pre>';
  131 + $this->addError ( 'Folder Not found' );
145 return false; 132 return false;
146 } 133 }
147 -  
148 - $types=(isset($arr['types']) ? $arr['types'] : 'DF');  
149 134
150 - $listing=$folder->get_listing(1, $types);  
151 -  
152 - $result=$this->_processListing($listing, 'grid', $arr); 135 + $types = (isset ( $arr ['types'] ) ? $arr ['types'] : 'DF');
153 136
154 - $this->setResponse(array('totalCount'=>count($listing), 'items'=>$result)); 137 + $listing = $folder->get_listing ( 1, $types );
  138 +
  139 + $result = $this->_processListing ( $listing, 'grid', $arr );
  140 +
  141 + $this->setResponse ( array ('totalCount' => count ( $listing ), 'items' => $result ) );
155 142
156 return true; 143 return true;
157 } 144 }
158 -  
159 -  
160 145
161 - private function _processListing($listing, $type, $arr){  
162 - $result=array();  
163 - $methodToIncludeItem='_processItemInclusion_'.$type;  
164 -  
165 - foreach($listing as $item){ 146 + private function _processListing($listing, $type, $arr) {
  147 + $this->logTrace ( __CLASS__ . '::' . __METHOD__ . '(' . __FILE__ . ' ' . __LINE__, 'Enter Function' );
  148 + $result = array ();
  149 + $methodToIncludeItem = '_processItemInclusion_' . $type;
  150 +
  151 + foreach ( $listing as $item ) {
166 /* Trying to fix folder sizes */ 152 /* Trying to fix folder sizes */
167 - if($item['filesize']<=0){  
168 - $item['filesize']='';  
169 - }else{  
170 - $item['filesize']=serviceHelper::size_readable($item['filesize']); 153 + if ($item ['filesize'] <= 0) {
  154 + $item ['filesize'] = '';
  155 + } else {
  156 + $item ['filesize'] = serviceHelper::size_readable ( $item ['filesize'] );
171 } 157 }
172 158
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, '); 159 + $filename = $item ['filename'];
  160 + $itemType = $item ['item_type'];
  161 +
  162 + $includeMe = true;
  163 + $qtip = '';
  164 + $canWrite = false;
  165 + $immutable = false;
  166 + $permissions = $item ['permissions'];
  167 + $perms = '';
  168 +
  169 + for($j = 0; $j < strlen ( $permissions ); $j ++) {
  170 + switch (strtoupper ( $permissions {$j} )) {
  171 + case 'W' :
  172 + $canWrite = true;
  173 + $perms .= $this->xlate ( 'write, ' );
188 break; 174 break;
189 - case 'R':  
190 - $perms .= $this->xlate('read, '); 175 + case 'R' :
  176 + $perms .= $this->xlate ( 'read, ' );
191 break; 177 break;
192 - case 'A':  
193 - $perms .= $this->xlate('add folder, '); 178 + case 'A' :
  179 + $perms .= $this->xlate ( 'add folder, ' );
194 break; 180 break;
195 } 181 }
196 } 182 }
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'); 183 +
  184 + if (strlen ( $perms ) > 2) {
  185 + $perms = substr ( $perms, 0, strlen ( $perms ) - 2 );
207 } 186 }
  187 +
  188 + if ($itemType == 'F') {
  189 + $qtip .= $this->xlate ( 'Folder name' ) . ": {$filename}<br>";
  190 + $class = 'folder';
  191 + $qtip .= $this->xlate ( 'Permissions:' ) . " {$perms}<br>";
  192 + $qtip .= $canWrite ? $this->xlate ( 'You may add content to this folder' ) : $this->xlate ( 'You may not add content to this folder' );
  193 + }
208 194
209 //documents 195 //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 196 + else {
  197 + $qtip = '';
  198 + $extpos = strrpos ( $filename, '.' );
  199 +
  200 + if ($extpos === false) {
  201 + $class = 'file-unknown';
  202 + } else {
  203 + $ext = substr ( $filename, $extpos ); // Get Extension including the dot
  204 + $class = 'file-' . substr ( $filename, $extpos + 1 ); // Get Extension without the dot
219 } 205 }
220 206
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; 207 + $extensions = explode ( ',', $arr ['extensions'] );
  208 + if (! in_array ( strtolower ( $ext ), $extensions ) && ! in_array ( '*', $extensions )) {
  209 + $includeMe = false;
  210 + } else {
  211 + $qtip .= $this->xlate ( 'Filename' ) . ": {$filename}<br>";
  212 + $qtip .= $this->xlate ( 'File Size' ) . ": " . serviceHelper::fsize_desc ( $item ['filesize'] ) . "<br>";
  213 + $qtip .= $this->xlate ( 'Modified' ) . ": {$item['modified_date']}<br>";
  214 + $qtip .= $this->xlate ( 'Owner' ) . ": {$item['created_by']}<br>";
  215 + $qtip .= $this->xlate ( 'Version' ) . ": {$item['version']}<br>";
  216 + if (serviceHelper::bool2str ( strtolower ( $item ['is_immutable'] ) ) == 'true') {
  217 + $canWrite = false;
  218 + $immutable = true;
233 } 219 }
234 220
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>'; 221 + if ($immutable) {
  222 + $qtip .= $this->xlate ( 'Status: Immutable' ) . '<br>';
  223 + } else if (strtolower ( $item ['checked_out_by'] ) != 'n/a' && ($item ['checked_out_by'] != '')) {
  224 + $qtip .= $this->xlate ( 'Status: Checked out by' ) . " {$item['checked_out_by']}<br>";
  225 + } else {
  226 + $qtip .= $this->xlate ( 'Status: Available' ) . '<br>';
241 } 227 }
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'); 228 + $qtip .= $this->xlate ( 'Permissions:' ) . " {$perms}<br>";
  229 +
  230 + if ($immutable) {
  231 + $qtip .= $this->xlate ( 'This document is not editable' );
  232 + } else if ($canWrite) {
  233 + $qtip .= $this->xlate ( 'You may edit this document' );
  234 + } else {
  235 + $qtip .= $this->xlate ( 'This document is not editable' );
250 } 236 }
251 } 237 }
252 - }//end of if for files  
253 - if($includeMe){  
254 - $result[]=$this->$methodToIncludeItem($item, $class, $qtip); 238 + } //end of if for files
  239 + if ($includeMe) {
  240 + $result [] = $this->$methodToIncludeItem ( $item, $class, $qtip );
255 } 241 }
256 } 242 }
257 return $result; 243 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 - } 244 + }
  245 +
  246 + private function _processItemInclusion_folderContents($item, $class, $qtip) {
  247 + $this->logTrace ( __CLASS__ . '::' . __METHOD__ . '(' . __FILE__ . ' ' . __LINE__, 'Enter Function' );
  248 + return array ('text' => htmlspecialchars ( $item ['title'] ), 'originaltext' => $item ['title'], 'id' => ($item ['item_type'] == 'F' ? $item ['item_type'] . "_" : "") . $item ['id'], 'filename' => $item ['filename'], 'cls' => $class, 'leaf' => ($item ['item_type'] == 'D'), 'document_type' => $item ['document_type'], 'item_type' => $item ['item_type'], 'permissions' => $item ['permissions'], 'content_id' => $item ['content_id'], 'checked_out_by' => $item ['checked_out_by'], 'qtip' => $qtip );
  249 + }
  250 +
  251 + private function _processItemInclusion_search($item, $class, $qtip) {
  252 + $this->logTrace ( __CLASS__ . '::' . __METHOD__ . '(' . __FILE__ . ' ' . __LINE__, 'Enter Function' );
  253 + if ($item ['filesize'] == 'n/a') {
  254 + $item ['filesize'] = - 1;
  255 + }
  256 + return array ('text' => htmlspecialchars ( $item ['title'] ), 'originaltext' => $item ['title'], 'id' => $item ['document_id'], 'filename' => $item ['filename'], 'cls' => $class, 'leaf' => true, 'document_type' => $item ['document_type'], 'item_type' => 'D', 'permissions' => $item ['permissions'], 'content_id' => $item ['content_id'], 'filesize' => $item ['filesize'], 'modified' => $item ['modified_date'], 'created_date' => $item ['created_date'], 'checked_out_by' => $item ['checked_out_by'], 'relevance' => $item ['relevance'], 'qtip' => $qtip, 'version' => $item ['version'] );
  257 + }
  258 +
  259 + private function _processItemInclusion_grid($item, $class, $qtip) {
  260 + $this->logTrace ( __CLASS__ . '::' . __METHOD__ . '(' . __FILE__ . ' ' . __LINE__, 'Enter Function' );
  261 + //var_dump($item);
  262 +
306 263
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 - 264 + if ($item ['filesize'] == 'n/a') {
  265 + $item ['filesize'] = - 1;
  266 + }
  267 +
  268 + return array ('text' => htmlspecialchars ( $item ['title'] ), 'originaltext' => $item ['title'], 'id' => $item ['id'], 'filename' => $item ['filename'], 'cls' => $class, 'owner' => $item ['created_by'], 'document_type' => $item ['document_type'], 'item_type' => $item ['item_type'], 'permissions' => $item ['permissions'], 'created_date' => $item ['created_date'], 'content_id' => $item ['content_id'], 'filesize' => $item ['filesize'], 'modified' => $item ['modified_date'], 'checked_out_by' => $item ['checked_out_by'], 'version' => $item ['version'] );
  269 + }
  270 +
335 public function get_metadata($params) { 271 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); 272 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  273 + $kt = &$this->KT;
  274 +
  275 + if (substr ( $params ['document_id'], 0, 2 ) == 'D_') {
  276 + $params ['document_id'] = substr ( $params ['document_id'], 2 );
340 } 277 }
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 - 278 +
  279 + $document_id = ( int ) $params ['document_id'];
  280 + if ($document_id > 0) {
  281 + $document = $kt->get_document_by_id ( $params ['document_id'] );
  282 + $detail = $document->get_metadata ();
  283 + $document_detail = $document->get_detail ();
  284 + $title = $document_detail ['title'];
  285 + $document_type = $document_detail ['document_type'];
  286 +
  287 + } else {
  288 + if (isset ( $params ['document_type'] )) {
  289 + $document_type = $params ['document_type'];
  290 + } else {
  291 + $document_type = 'Default';
  292 + }
  293 + $detail = $kt->get_document_type_metadata ( $document_type );
  294 + $title = "";
  295 + }
  296 +
  297 + $result = array ();
  298 + $items = array ();
  299 + $index = 0;
  300 + $items [] = array ("name" => "__title", "index" => 0, "value" => $title, "control_type" => "string" );
  301 +
366 // Commented out for timebeing - will be used by 'Save in Format' 302 // Commented out for timebeing - will be used by 'Save in Format'
  303 +
367 304
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']))); 305 + if (isset ( $params ['extensions'] )) {
  306 +
  307 + $fileParts = pathinfo ( $document_detail ['filename'] );
  308 +
  309 + $items [] = array ("name" => "__document_extension", "index" => 0, "value" => strtolower ( $fileParts ['extension'] ), "control_type" => "lookup", "selection" => explode ( ',', str_replace ( '.', '', $params ['extensions'] ) ) );
373 } 310 }
  311 +
  312 + $document_types = $kt->get_documenttypes ( $params );
  313 + $items [] = array ("name" => "__document_type", "index" => 0, "value" => $document_type, "control_type" => "lookup", "selection" => $document_types );
  314 +
  315 + foreach ( $detail as $fieldset ) {
  316 + foreach ( $fieldset ['fields'] as $field ) {
  317 +
  318 + $prepArray = array ('fieldset' => $fieldset ['fieldset'], 'name' => $field ['name'],
374 319
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) { 320 + // Change for value. If blank value is set to 1, change value to ''
  321 + // Overcomes issue of n/a
  322 + 'value' => ($document_id > 0 ? ($field ['blankvalue'] == '1' ? '' : $field ['value']) : ''),
380 323
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']; 324 + 'description' => $field ['description'], 'control_type' => $field ['control_type'], 'selection' => $field ['selection'], 'required' => $field ['required'], 'blankvalue' => $field ['blankvalue'], 'index' => $index );
  325 +
  326 + // Small Adjustment for multiselect to real type
  327 + if ($field ['control_type'] == 'multiselect') {
  328 + $prepArray ['control_type'] = $field ['options'] ['type'];
  329 + }
  330 +
  331 + if (isset ( $field ['options'] ['ishtml'] )) {
  332 + $prepArray ['ishtml'] = $field ['options'] ['ishtml'];
405 } else { 333 } else {
406 - $prepArray['ishtml'] = '0'; 334 + $prepArray ['ishtml'] = '0';
407 } 335 }
408 336
409 - if (isset($field['options']['maxlength'])) {  
410 - $prepArray['maxlength'] = $field['options']['maxlength']; 337 + if (isset ( $field ['options'] ['maxlength'] )) {
  338 + $prepArray ['maxlength'] = $field ['options'] ['maxlength'];
411 } else { 339 } else {
412 - $prepArray['maxlength'] = '-1'; 340 + $prepArray ['maxlength'] = '-1';
413 } 341 }
414 -  
415 - $items[] = $prepArray;  
416 - $index++;  
417 - }  
418 - }  
419 -  
420 -  
421 -  
422 - $this->setResponse(array('id'=>$title, 'items'=>$items, 'count'=>count($items)));  
423 - 342 +
  343 + $items [] = $prepArray;
  344 + $index ++;
  345 + }
  346 + }
  347 +
  348 + $this->setResponse ( array ('id' => $title, 'items' => $items, 'count' => count ( $items ) ) );
  349 +
424 return true; 350 return true;
425 } 351 }
426 -  
427 - 352 +
428 public function get_documenttypes($params) { 353 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 - ); 354 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  355 +
  356 + $kt = &$this->KT;
  357 +
  358 + $detail = $kt->get_documenttypes ();
  359 + $result = array ();
  360 + $items = array ();
  361 + for($i = 0; $i < count ( $detail ); $i ++) {
  362 + if (strtolower ( substr ( $detail [$i], - 5 ) ) != 'email') {
  363 + $items [] = array ('name' => $detail [$i] );
441 } 364 }
442 } 365 }
443 - $this->setResponse(array('items'=>$items, 'count'=>count($items))); 366 + $this->setResponse ( array ('items' => $items, 'count' => count ( $items ) ) );
444 return true; 367 return true;
445 } 368 }
446 - 369 +
447 function update_document_type($params) { 370 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 - 371 + $kt = &$this->KT;
  372 + $document_id = ( int ) $params ['document_id'];
  373 + if ($document_id > 0) {
  374 + $document = $kt->get_document_by_id ( $document_id );
  375 + $document->change_document_type ( $params ['document_type'] );
  376 + $this->setResponse ( array ('status_code' => 0 ) );
  377 + return true;
  378 +
  379 + } else {
  380 + $this->addError ( "Invalid document Id : {$document_id}" );
  381 + $this->setResponse ( array ('status_code' => 1 ) );
  382 + return false;
  383 + }
  384 +
462 } 385 }
463 - 386 +
464 /** 387 /**
465 * Get a url for downloading the specified document 388 * Get a url for downloading the specified document
466 * Parameters: 389 * Parameters:
@@ -470,91 +393,86 @@ class kt extends client_service { @@ -470,91 +393,86 @@ class kt extends client_service {
470 * 393 *
471 * @param unknown_type $params 394 * @param unknown_type $params
472 */ 395 */
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 - $multipart=false;  
481 -  
482 - $this->Response->addDebug('download_document Parameters',$params);  
483 -  
484 -  
485 - $session_id=$params['session_id'];  
486 -  
487 -  
488 - $document=&$kt->get_document_by_id($params['document_id']);  
489 - // $docname='test.txt';  
490 - if (PEAR::isError($document))  
491 - {  
492 - $response['message']=$document->getMessage();  
493 - $this->addDebug("download_document - cannot get $document_id - " . $document->getMessage(), $document);  
494 -  
495 -// $this->setResponse(new SOAP_Value('$this->response=',"{urn:$this->namespace}kt_response", $response));  
496 - $this->setResponse($response);  
497 - return;  
498 - }  
499 - $docname=$document->document->getFileName();  
500 - $result=$document->download();  
501 - if (PEAR::isError($result))  
502 - {  
503 - $response['message']=$result->getMessage();  
504 - $this->setResponse(array('status_code'=>1, 'message'=>$result->getMessage())); 396 + function download_document($params, $returnResult = false){
  397 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  398 +
  399 + $kt = &$this->KT;
  400 + $params ['session_id'] = $params ['session_id'] ? $params ['session_id'] : $this->AuthInfo ['session'];
  401 + $params ['app_type'] = $params ['app_type'] ? $params ['app_type'] : $this->AuthInfo ['appType'];
  402 + $params ['app_type'] = 'air';
  403 + $multipart = isset ( $params ['multipart'] ) ? ( bool ) $params ['multipart'] : false;
  404 + $multipart = false;
  405 +
  406 + $this->Response->addDebug ( 'download_document Parameters', $params );
  407 +
  408 + $session_id = $params ['session_id'];
  409 +
  410 + $document = &$kt->get_document_by_id ( $params ['document_id'] );
  411 + // $docname='test.txt';
  412 + if (PEAR::isError ( $document )) {
  413 + $response ['message'] = $document->getMessage ();
  414 + $this->addDebug ( "download_document - cannot get $document_id - " . $document->getMessage (), $document );
  415 +
  416 + // $this->setResponse(new SOAP_Value('$this->response=',"{urn:$this->namespace}kt_response", $response));
  417 + $this->setResponse ( $response );
505 return; 418 return;
506 - }  
507 -  
508 - $session=&$kt->get_session();  
509 - $download_manager=new KTDownloadManager();  
510 - $download_manager->set_session($session->session);  
511 - $download_manager->cleanup();  
512 - $url=$download_manager->allow_download($document,NULL,$multipart);  
513 - //http://ktair.dev?code=750f7a09d40a3d855f2897f417baf0bbb9a1f615&d=16&u=evm2pdkkhfagon47eh2b9slqj6  
514 - /* 419 + }
  420 + $docname = $document->document->getFileName ();
  421 + $result = $document->download ();
  422 + if (PEAR::isError ( $result )) {
  423 + $response ['message'] = $result->getMessage ();
  424 + $this->setResponse ( array ('status_code' => 1, 'message' => $result->getMessage () ) );
  425 + return;
  426 + }
  427 +
  428 + $session = &$kt->get_session ();
  429 + $download_manager = new KTDownloadManager ( );
  430 + $download_manager->set_session ( $session->session );
  431 + $download_manager->cleanup ();
  432 + $url = $download_manager->allow_download ( $document, NULL, $multipart );
  433 + //http://ktair.dev?code=750f7a09d40a3d855f2897f417baf0bbb9a1f615&d=16&u=evm2pdkkhfagon47eh2b9slqj6
  434 + /*
515 $this->addDebug('url before split',$url); 435 $this->addDebug('url before split',$url);
516 $url=split('\?',$url); 436 $url=split('\?',$url);
517 $this->addDebug('url after split',$url); 437 $this->addDebug('url after split',$url);
518 $url=$url[0].'/ktwebservice/download.php?'.$url[1]; 438 $url=$url[0].'/ktwebservice/download.php?'.$url[1];
519 $this->addDebug('url after recombo',$url); 439 $this->addDebug('url after recombo',$url);
520 */ 440 */
521 -  
522 - $response['status_code']=0;  
523 - $response['message']=$url.'&apptype='.$params['app_type'];  
524 - $response['filename']=$docname;  
525 -  
526 - $this->addDebug('effective params',$params);  
527 -  
528 - if($returnResult){  
529 - return $response;  
530 - }else{  
531 - $this->setResponse($response);  
532 - }  
533 - }  
534 -  
535 - /**  
536 - * Get download URLS for multiple documents  
537 - * params contains:  
538 - * app_type  
539 - * documents = array of doc_id  
540 - *  
541 - * @param unknown_type $params  
542 - */  
543 - public function download_multiple_documents($params){  
544 - $response=array();  
545 - foreach($params['documents'] as $docId){  
546 - $ret=$this->download_document(array('document_id'=>$docId,'app_type'=>$params['app_type'],'multipart'=>$params['multipart']),true);  
547 - $this->Response->addDebug('Trying to create Download Link for '.$docId,$ret);  
548 - $rec=array(  
549 - 'filename' =>$ret['filename'],  
550 - 'url' =>$ret['message'],  
551 - 'succeeded' =>$ret['status_code']==0?true:false  
552 - );  
553 - if(is_array($ret))$response[$docId]=$rec;  
554 - }  
555 - $this->setResponse($response);  
556 - }  
557 - 441 +
  442 + $response ['status_code'] = 0;
  443 + $response ['message'] = $url . '&apptype=' . $params ['app_type'];
  444 + $response ['filename'] = $docname;
  445 +
  446 + $this->addDebug ( 'effective params', $params );
  447 +
  448 + if ($returnResult) {
  449 + return $response;
  450 + } else {
  451 + $this->setResponse ( $response );
  452 + }
  453 + }
  454 +
  455 + /**
  456 + * Get download URLS for multiple documents
  457 + * params contains:
  458 + * app_type
  459 + * documents = array of doc_id
  460 + *
  461 + * @param unknown_type $params
  462 + */
  463 + public function download_multiple_documents($params) {
  464 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  465 + $response = array ();
  466 + foreach ( $params ['documents'] as $docId ) {
  467 + $ret = $this->download_document ( array ('document_id' => $docId, 'app_type' => $params ['app_type'], 'multipart' => $params ['multipart'] ), true );
  468 + $this->Response->addDebug ( 'Trying to create Download Link for ' . $docId, $ret );
  469 + $rec = array ('filename' => $ret ['filename'], 'url' => $ret ['message'], 'succeeded' => $ret ['status_code'] == 0 ? true : false );
  470 + if (is_array ( $ret ))
  471 + $response [$docId] = $rec;
  472 + }
  473 + $this->setResponse ( $response );
  474 + }
  475 +
558 /** 476 /**
559 * Checkout a Document 477 * Checkout a Document
560 * params contains: 478 * params contains:
@@ -564,39 +482,36 @@ class kt extends client_service { @@ -564,39 +482,36 @@ class kt extends client_service {
564 * @param array $params 482 * @param array $params
565 * 483 *
566 */ 484 */
567 - function checkout_document($params){  
568 - $responseType='kt_response';  
569 - $kt=&$this->KT;  
570 -  
571 - $document=&$kt->get_document_by_id($params['document_id']);  
572 - if (PEAR::isError($document))  
573 - {  
574 - $this->addError("checkout_document - cannot get documentid {$params['document_id']} - " . $document->getMessage());  
575 - $this->setResponse(array('status_code'=>1, 'message'=>$document->getMessage())); 485 + function checkout_document($params) {
  486 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  487 + $responseType = 'kt_response';
  488 + $kt = &$this->KT;
  489 +
  490 + $document = &$kt->get_document_by_id ( $params ['document_id'] );
  491 + if (PEAR::isError ( $document )) {
  492 + $this->addError ( "checkout_document - cannot get documentid {$params['document_id']} - " . $document->getMessage () );
  493 + $this->setResponse ( array ('status_code' => 1, 'message' => $document->getMessage () ) );
576 return; 494 return;
577 - }  
578 -  
579 - $result=$document->checkout($params['reason']);  
580 - if (PEAR::isError($result))  
581 - {  
582 - $this->addError($result->getMessage());  
583 - $this->setResponse(array('status_code'=>1, 'message'=>$result->getMessage()));  
584 - return;  
585 - }  
586 -  
587 - $url='';  
588 - if ($params['download'])  
589 - {  
590 - $download_manager=new KTDownloadManager();  
591 - $download_manager->set_session($params['session_id']);  
592 - $download_manager->cleanup();  
593 - $url=$download_manager->allow_download($document);  
594 - }  
595 -  
596 - $this->setResponse(array('status_code'=>0, 'message'=>$url));  
597 - }  
598 -  
599 - 495 + }
  496 +
  497 + $result = $document->checkout ( $params ['reason'] );
  498 + if (PEAR::isError ( $result )) {
  499 + $this->addError ( $result->getMessage () );
  500 + $this->setResponse ( array ('status_code' => 1, 'message' => $result->getMessage () ) );
  501 + return;
  502 + }
  503 +
  504 + $url = '';
  505 + if ($params ['download']) {
  506 + $download_manager = new KTDownloadManager ( );
  507 + $download_manager->set_session ( $params ['session_id'] );
  508 + $download_manager->cleanup ();
  509 + $url = $download_manager->allow_download ( $document );
  510 + }
  511 +
  512 + $this->setResponse ( array ('status_code' => 0, 'message' => $url ) );
  513 + }
  514 +
600 /** 515 /**
601 * Checkin Document //TODO: Find out how upload works 516 * Checkin Document //TODO: Find out how upload works
602 * params contains: 517 * params contains:
@@ -607,688 +522,692 @@ class kt extends client_service { @@ -607,688 +522,692 @@ class kt extends client_service {
607 * 522 *
608 * @param array $params 523 * @param array $params
609 */ 524 */
610 - function checkin_document($params){  
611 - $session_id=$this->AuthInfo['session'];  
612 - $document_id=$params['document_id'];  
613 - $filename=$params['filename'];  
614 - $reason=$params['reason'];  
615 - $tempfilename=$params['tempfilename'];  
616 - $major_update=$params['major_update'];  
617 - $application=$this->AuthInfo['appType'];  
618 -  
619 - $this->addDebug('Checkin',"checkin_document('$session_id',$document_id,'$filename','$reason','$tempfilename', '$application', $major_update)");  
620 - $kt=&$this->KT;  
621 -  
622 - // we need to add some security to ensure that people don't frig the checkin process to access restricted files. 525 + function checkin_document($params) {
  526 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  527 + $session_id = $this->AuthInfo ['session'];
  528 + $document_id = $params ['document_id'];
  529 + $filename = $params ['filename'];
  530 + $reason = $params ['reason'];
  531 + $tempfilename = $params ['tempfilename'];
  532 + $major_update = $params ['major_update'];
  533 + $application = $this->AuthInfo ['appType'];
  534 +
  535 + $this->addDebug ( 'Checkin', "checkin_document('$session_id',$document_id,'$filename','$reason','$tempfilename', '$application', $major_update)" );
  536 + $kt = &$this->KT;
  537 +
  538 + // we need to add some security to ensure that people don't frig the checkin process to access restricted files.
623 // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome. 539 // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome.
624 - $upload_manager=new KTUploadManager();  
625 - if (!$upload_manager->is_valid_temporary_file($tempfilename))  
626 - {  
627 - $this->setResponse(array('status_code'=>12)); 540 + $upload_manager = new KTUploadManager ( );
  541 + if (! $upload_manager->is_valid_temporary_file ( $tempfilename )) {
  542 + $this->setResponse ( array ('status_code' => 12 ) );
628 return; 543 return;
629 - }  
630 -  
631 - $document=&$kt->get_document_by_id($document_id);  
632 - if (PEAR::isError($document))  
633 - {  
634 - $this->setResponse(array('status_code'=>13));  
635 } 544 }
636 - 545 +
  546 + $document = &$kt->get_document_by_id ( $document_id );
  547 + if (PEAR::isError ( $document )) {
  548 + $this->setResponse ( array ('status_code' => 13 ) );
  549 + }
  550 +
637 // checkin 551 // checkin
638 - $result=$document->checkin($filename, $reason, $tempfilename, $major_update);  
639 - if (PEAR::isError($result))  
640 - {  
641 - $this->setResponse(array('status_code'=>14)); 552 + $result = $document->checkin ( $filename, $reason, $tempfilename, $major_update );
  553 + if (PEAR::isError ( $result )) {
  554 + $this->setResponse ( array ('status_code' => 14 ) );
642 } 555 }
643 -  
644 - // get status after checkin 556 +
  557 + // get status after checkin
645 //$this->response= $this->get_document_detail($session_id, $document_id); 558 //$this->response= $this->get_document_detail($session_id, $document_id);
646 - $detail=$document->get_detail();  
647 - $detail['status_code']=0;  
648 - $detail['message']='';  
649 -  
650 - $this->setResponse($detail);  
651 - }  
652 -  
653 -  
654 - /**  
655 - * Upload a document  
656 - *  
657 - * @param unknown_type $arr  
658 - */  
659 - function add_document_with_metadata($arr){  
660 - $session_id=$arr['session_id'];  
661 - //error_reporting(E_ALL);  
662 - $metadata=array();  
663 - $packed=$arr['metadata'];  
664 -  
665 - foreach($meta as $item){  
666 - $fieldSet=$item['fieldset'];  
667 - unset($item['fieldset']);  
668 - $metadata[$fieldSet]['fieldset']=$fieldSet;  
669 - $metadata[$fieldSet]['fields'][]=$item;  
670 - }  
671 -  
672 - $kt=&$this->KT;  
673 -  
674 - $upload_manager=new KTUploadManager();  
675 - if (!$upload_manager->is_valid_temporary_file($arr['tempfilename'])) {  
676 - $this->addError('Temporary File Not Valid');  
677 - $this->setResponse(array('status_code'=>1, 'message'=>'Temporary File Not Valid')); 559 + $detail = $document->get_detail ();
  560 + $detail ['status_code'] = 0;
  561 + $detail ['message'] = '';
  562 +
  563 + $this->setResponse ( $detail );
  564 + }
  565 +
  566 + /**
  567 + * Upload a document
  568 + *
  569 + * @param unknown_type $arr
  570 + */
  571 + function add_document_with_metadata($arr) {
  572 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  573 + $session_id = $arr ['session_id'];
  574 + //error_reporting(E_ALL);
  575 + $metadata = array ();
  576 + $packed = $arr ['metadata'];
  577 +
  578 + foreach ( $meta as $item ) {
  579 + $fieldSet = $item ['fieldset'];
  580 + unset ( $item ['fieldset'] );
  581 + $metadata [$fieldSet] ['fieldset'] = $fieldSet;
  582 + $metadata [$fieldSet] ['fields'] [] = $item;
  583 + }
  584 +
  585 + $kt = &$this->KT;
  586 +
  587 + $upload_manager = new KTUploadManager ( );
  588 + if (! $upload_manager->is_valid_temporary_file ( $arr ['tempfilename'] )) {
  589 + $this->addError ( 'Temporary File Not Valid' );
  590 + $this->setResponse ( array ('status_code' => 1, 'message' => 'Temporary File Not Valid' ) );
678 return false; 591 return false;
679 - }  
680 - $this->addDebug('','Exited is_valid_temporary file');  
681 -  
682 - $folder=&$kt->get_folder_by_id($arr['folder_id']);  
683 - if (PEAR::isError($folder)){  
684 - $this->addError('Could not find Folder '.$arr['folder_id']);  
685 - $this->setResponse(array('status_code'=>1, 'message'=>'Could not find Folder '.$arr['folder_id']));  
686 - return false;  
687 } 592 }
  593 + $this->addDebug ( '', 'Exited is_valid_temporary file' );
688 594
689 - $document=&$folder->add_document($arr['title'], $arr['filename'], $arr['documenttype'], $arr['tempfilename']);  
690 - if (PEAR::isError($document)){  
691 - $this->addError("Could not add Document [title:{$title},filename:{$filename},documenttype:{$documenttype},tempfilename:{$tempfilename}]");  
692 - $this->setResponse(array('status_code'=>1, 'message'=>'Could not add Document'));  
693 - return false; 595 + $folder = &$kt->get_folder_by_id ( $arr ['folder_id'] );
  596 + if (PEAR::isError ( $folder )) {
  597 + $this->addError ( 'Could not find Folder ' . $arr ['folder_id'] );
  598 + $this->setResponse ( array ('status_code' => 1, 'message' => 'Could not find Folder ' . $arr ['folder_id'] ) );
  599 + return false;
694 } 600 }
695 -  
696 -  
697 - $document_id=$document->get_documentid();  
698 -  
699 - $update_result=$this->update_document_metadata($arr['session_id'], $document_id, $metadata, $arr['application'], array());  
700 -  
701 - $status_code=$update_result['status_code'];  
702 - if ($status_code != 0)  
703 - {  
704 - $this->delete_document(array('session_id' => $arr['session_id'], 'document_id' => $document_id, 'reason' => 'Rollback because metadata could not be added', 'application' => $arr['application']));  
705 - $this->response= $update_result; 601 +
  602 + $document = &$folder->add_document ( $arr ['title'], $arr ['filename'], $arr ['documenttype'], $arr ['tempfilename'] );
  603 + if (PEAR::isError ( $document )) {
  604 + $this->addError ( "Could not add Document [title:{$title},filename:{$filename},documenttype:{$documenttype},tempfilename:{$tempfilename}]" );
  605 + $this->setResponse ( array ('status_code' => 1, 'message' => 'Could not add Document' ) );
  606 + return false;
706 } 607 }
707 -  
708 -  
709 - $result=$document->mergeWithLastMetadataVersion();  
710 - if (PEAR::isError($result))  
711 - { 608 +
  609 + $document_id = $document->get_documentid ();
  610 +
  611 + $update_result = $this->update_document_metadata ( $arr ['session_id'], $document_id, $metadata, $arr ['application'], array () );
  612 +
  613 + $status_code = $update_result ['status_code'];
  614 + if ($status_code != 0) {
  615 + $this->delete_document ( array ('session_id' => $arr ['session_id'], 'document_id' => $document_id, 'reason' => 'Rollback because metadata could not be added', 'application' => $arr ['application'] ) );
  616 + $this->response = $update_result;
  617 + }
  618 +
  619 + $result = $document->mergeWithLastMetadataVersion ();
  620 + if (PEAR::isError ( $result )) {
712 // not much we can do, maybe just log! 621 // not much we can do, maybe just log!
713 } 622 }
714 -  
715 - $this->response= array('status_code'=>0, 'document_id'=>$document_id);  
716 - } 623 +
  624 + $this->response = array ('status_code' => 0, 'document_id' => $document_id );
  625 + }
717 626
718 - function create_empty_upload_file($params){  
719 - $config=KTConfig::getSingleton();  
720 - $this->addDebug('KTConfig Singleton',$config);  
721 - $uploadFolder=$config->get('webservice/uploadDirectory'); 627 + function create_empty_upload_file($params) {
  628 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  629 + $config = KTConfig::getSingleton ();
  630 + $this->addDebug ( 'KTConfig Singleton', $config );
  631 + $uploadFolder = $config->get ( 'webservice/uploadDirectory' );
722 632
723 - $result = array(); 633 + $result = array ();
724 634
725 - if ($file = fopen($uploadFolder."/".$params['filename'], 'w')) {  
726 - fclose($file);  
727 - $result['status_code'] = '0';  
728 - $result['filename'] = $uploadFolder."/".$params['filename']; 635 + if ($file = fopen ( $uploadFolder . "/" . $params ['filename'], 'w' )) {
  636 + fclose ( $file );
  637 + $result ['status_code'] = '0';
  638 + $result ['filename'] = $uploadFolder . "/" . $params ['filename'];
729 } else { 639 } else {
730 - $result['status_code'] = '1';  
731 - $result['filename'] = $uploadFolder."/".$params['filename']; 640 + $result ['status_code'] = '1';
  641 + $result ['filename'] = $uploadFolder . "/" . $params ['filename'];
732 } 642 }
733 - $this->setResponse($result); 643 + $this->setResponse ( $result );
734 return true; 644 return true;
735 } 645 }
736 -  
737 - function get_all_client_policies(){  
738 - $config=KTConfig::getSingleton();  
739 - $this->addDebug('KTConfig Singleton',$config); 646 +
  647 + function get_all_client_policies() {
  648 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  649 + $config = KTConfig::getSingleton ();
  650 + $this->addDebug ( 'KTConfig Singleton', $config );
740 651
741 - $policies=array('allowRememberPassword', 'captureReasonsCheckin', 'captureReasonsCheckout'); 652 + $policies = array ('allowRememberPassword', 'captureReasonsCheckin', 'captureReasonsCheckout' );
742 653
743 - $returnPolicies=array(); 654 + $returnPolicies = array ();
744 655
745 - foreach ($policies as $policy_name)  
746 - {  
747 - $policyInfo=array(  
748 - 'name'=>$policy_name,  
749 - 'value'=>serviceHelper::bool2str($config->get('addInPolicies/'.$policy_name)),  
750 - 'type'=>'boolean'  
751 - ); 656 + foreach ( $policies as $policy_name ) {
  657 + $policyInfo = array ('name' => $policy_name, 'value' => serviceHelper::bool2str ( $config->get ( 'addInPolicies/' . $policy_name ) ), 'type' => 'boolean' );
752 658
753 - $returnPolicies[$policy_name] =$policyInfo; 659 + $returnPolicies [$policy_name] = $policyInfo;
754 } 660 }
755 661
756 - $languages=$this->get_languages(true);  
757 -  
758 - $metadata=array('totalProperty'=>'resultsCounter', 'root'=>'languages', 'fields'=>array('isoCode', 'language')); 662 + $languages = $this->get_languages ( true );
759 663
760 - $finalArray=array();  
761 - $finalArray['metaData']=$metadata;  
762 - $finalArray['policies']=$returnPolicies;  
763 - $finalArray['languages']=$languages['languages'];  
764 - $finalArray['defaultLanguage']=$languages['defaultLanguage'];  
765 - $finalArray['resultsCounter']=$languages['count']; 664 + $metadata = array ('totalProperty' => 'resultsCounter', 'root' => 'languages', 'fields' => array ('isoCode', 'language' ) );
766 665
  666 + $finalArray = array ();
  667 + $finalArray ['metaData'] = $metadata;
  668 + $finalArray ['policies'] = $returnPolicies;
  669 + $finalArray ['languages'] = $languages ['languages'];
  670 + $finalArray ['defaultLanguage'] = $languages ['defaultLanguage'];
  671 + $finalArray ['resultsCounter'] = $languages ['count'];
767 672
768 - $this->setResponse($finalArray); 673 + $this->setResponse ( $finalArray );
769 return true; 674 return true;
770 } 675 }
771 -  
772 - function get_all_explorer_policies(){  
773 - $config=KTConfig::getSingleton();  
774 - $this->addDebug('KTConfig Singleton',$config); 676 +
  677 + function get_all_explorer_policies() {
  678 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  679 + $config = KTConfig::getSingleton ();
  680 + $this->addDebug ( 'KTConfig Singleton', $config );
775 681
776 - $policies=array('allowRememberPassword', 'explorerMetadataCapture', 'officeMetadataCapture', 'captureReasonsCheckin', 'captureReasonsCheckout', 'captureReasonsDelete', 'captureReasonsCancelCheckout', 'captureReasonsCopyInKT', 'captureReasonsMoveInKT'); 682 + $policies = array ('allowRememberPassword', 'explorerMetadataCapture', 'officeMetadataCapture', 'captureReasonsCheckin', 'captureReasonsCheckout', 'captureReasonsDelete', 'captureReasonsCancelCheckout', 'captureReasonsCopyInKT', 'captureReasonsMoveInKT' );
777 683
778 - $returnPolicies=array();  
779 - $test = $config->get('clientToolPolicies/allowRememberPassword'); 684 + $returnPolicies = array ();
  685 + $test = $config->get ( 'clientToolPolicies/allowRememberPassword' );
780 global $default; 686 global $default;
781 - $default->log->error('I am here-'.$test);  
782 - foreach ($policies as $policy_name)  
783 - {  
784 - $policyInfo=array(  
785 - 'name'=>$policy_name,  
786 - 'value'=>serviceHelper::bool2str($config->get('clientToolPolicies/'.$policy_name)),  
787 - 'type'=>'boolean'  
788 - ); 687 + $default->log->error ( 'I am here-' . $test );
  688 + foreach ( $policies as $policy_name ) {
  689 + $policyInfo = array ('name' => $policy_name, 'value' => serviceHelper::bool2str ( $config->get ( 'clientToolPolicies/' . $policy_name ) ), 'type' => 'boolean' );
789 690
790 - $returnPolicies[$policy_name] =$policyInfo; 691 + $returnPolicies [$policy_name] = $policyInfo;
791 } 692 }
792 693
793 - $languages=$this->get_languages(true);  
794 -  
795 - $metadata=array('totalProperty'=>'resultsCounter', 'root'=>'languages', 'fields'=>array('isoCode', 'language')); 694 + $languages = $this->get_languages ( true );
796 695
797 - $finalArray=array();  
798 - $finalArray['metaData']=$metadata;  
799 - $finalArray['policies']=$returnPolicies;  
800 - $finalArray['languages']=$languages['languages'];  
801 - $finalArray['defaultLanguage']=$languages['defaultLanguage'];  
802 - $finalArray['resultsCounter']=$languages['count']; 696 + $metadata = array ('totalProperty' => 'resultsCounter', 'root' => 'languages', 'fields' => array ('isoCode', 'language' ) );
803 697
  698 + $finalArray = array ();
  699 + $finalArray ['metaData'] = $metadata;
  700 + $finalArray ['policies'] = $returnPolicies;
  701 + $finalArray ['languages'] = $languages ['languages'];
  702 + $finalArray ['defaultLanguage'] = $languages ['defaultLanguage'];
  703 + $finalArray ['resultsCounter'] = $languages ['count'];
804 704
805 - $this->setResponse($finalArray); 705 + $this->setResponse ( $finalArray );
806 return true; 706 return true;
807 } 707 }
808 708
809 - public function switchlang($params){  
810 - setcookie("kt_language", $params['lang'], 2147483647, '/'); 709 + public function switchlang($params) {
  710 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  711 + setcookie ( "kt_language", $params ['lang'], 2147483647, '/' );
811 } 712 }
812 -  
813 -  
814 - function add_document_params($params){  
815 - $folder_id=$params['folder_id'];  
816 - $title=$params['title'];  
817 - $filename=$params['filename'];  
818 - $documenttype=$params['documenttype'];  
819 - $tempfilename=$params['tempfilename'];  
820 - $application=$params['application'];  
821 -  
822 - $this->addDebug('','Entered add_document');  
823 - $kt=&$this->KT;  
824 -  
825 - $upload_manager=new KTUploadManager();  
826 - if (!$upload_manager->is_valid_temporary_file($tempfilename)) {  
827 - $this->addError('Temporary File Not Valid');  
828 - $this->setResponse(array('status_code'=>1)); 713 +
  714 + function add_document_params($params) {
  715 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  716 + $folder_id = $params ['folder_id'];
  717 + $title = $params ['title'];
  718 + $filename = $params ['filename'];
  719 + $documenttype = $params ['documenttype'];
  720 + $tempfilename = $params ['tempfilename'];
  721 + $application = $params ['application'];
  722 +
  723 + $this->addDebug ( '', 'Entered add_document' );
  724 + $kt = &$this->KT;
  725 +
  726 + $upload_manager = new KTUploadManager ( );
  727 + if (! $upload_manager->is_valid_temporary_file ( $tempfilename )) {
  728 + $this->addError ( 'Temporary File Not Valid' );
  729 + $this->setResponse ( array ('status_code' => 1 ) );
829 return false; 730 return false;
830 - }  
831 - $this->addDebug('','Exited is_valid_temporary file');  
832 -  
833 - $folder=&$kt->get_folder_by_id($folder_id);  
834 - if (PEAR::isError($folder)){  
835 - $this->addError('Could not find Folder '.$folder_id);  
836 - $this->setResponse(array('status_code'=>1));  
837 - return false;  
838 } 731 }
839 -  
840 - $this->addDebug('','Exited get_folder_by_id');  
841 -  
842 - $document=&$folder->add_document($title, $filename, $documenttype, $tempfilename);  
843 - if (PEAR::isError($document)){  
844 - $this->addError("Could add Document [title:{$title},filename:{$filename},documenttype:{$documenttype},tempfilename:{$tempfilename}]");  
845 - $this->setResponse(array('status_code'=>1));  
846 - return false; 732 + $this->addDebug ( '', 'Exited is_valid_temporary file' );
  733 +
  734 + $folder = &$kt->get_folder_by_id ( $folder_id );
  735 + if (PEAR::isError ( $folder )) {
  736 + $this->addError ( 'Could not find Folder ' . $folder_id );
  737 + $this->setResponse ( array ('status_code' => 1 ) );
  738 + return false;
847 } 739 }
848 -  
849 - $this->addDebug('','Exited folder add_document');  
850 -  
851 - $detail=$document->get_detail();  
852 - $detail['status_code']=0;  
853 - $detail['message']='';  
854 -  
855 - $this->setResponse($detail);  
856 - } 740 +
  741 + $this->addDebug ( '', 'Exited get_folder_by_id' );
  742 +
  743 + $document = &$folder->add_document ( $title, $filename, $documenttype, $tempfilename );
  744 + if (PEAR::isError ( $document )) {
  745 + $this->addError ( "Could add Document [title:{$title},filename:{$filename},documenttype:{$documenttype},tempfilename:{$tempfilename}]" );
  746 + $this->setResponse ( array ('status_code' => 1 ) );
  747 + return false;
  748 + }
  749 +
  750 + $this->addDebug ( '', 'Exited folder add_document' );
  751 +
  752 + $detail = $document->get_detail ();
  753 + $detail ['status_code'] = 0;
  754 + $detail ['message'] = '';
  755 +
  756 + $this->setResponse ( $detail );
  757 + }
857 758
858 - function delete_document($params){  
859 - $session_id = $params['session_id'];  
860 - $document_id = $params['document_id'];  
861 - $reason = $params['reason'];  
862 - $application = $params['application']; 759 + function delete_document($params) {
  760 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  761 + $session_id = $params ['session_id'];
  762 + $document_id = $params ['document_id'];
  763 + $reason = $params ['reason'];
  764 + $application = $params ['application'];
863 765
864 - $kt=&$this->KT;  
865 -  
866 - $document=&$kt->get_document_by_id($document_id);  
867 - if (PEAR::isError($document)){  
868 - $this->addError("Invalid document {$document_id}");  
869 - $this->setResponse(array('status_code'=>1));  
870 - return false;  
871 - }  
872 -  
873 - $result=$document->delete($reason);  
874 - if (PEAR::isError($result)) {  
875 - $this->addError("Could not delete document {$document_id}");  
876 - $this->setResponse(array('status_code'=>1));  
877 - return false;  
878 - }  
879 - $this->setResponse(array('status_code'=>0));  
880 - return true;  
881 - }  
882 -  
883 -  
884 -  
885 - private function update_document_metadata($session_id, $document_id, $metadata, $application, $sysdata=null){  
886 - $this->addDebug('update_document_metadata','entered update_document_metadata');  
887 - $kt=&$this->KT;  
888 - $responseType='kt_document_detail';  
889 -  
890 - $document=&$kt->get_document_by_id($document_id);  
891 - if (PEAR::isError($document)){  
892 - return array('status_code'=>1, 'error'=>'Error getting document');  
893 - }  
894 -  
895 - $result=$document->update_metadata($metadata);  
896 - if (PEAR::isError($result)){  
897 - return array('status_code'=>1, 'error'=>'Error updating metadata');  
898 - }  
899 -  
900 - $result=$document->update_sysdata($sysdata);  
901 - if (PEAR::isError($result)){  
902 - return array('status_code'=>1, 'error'=>'Error update_sysdata'); 766 + $kt = &$this->KT;
  767 +
  768 + $document = &$kt->get_document_by_id ( $document_id );
  769 + if (PEAR::isError ( $document )) {
  770 + $this->addError ( "Invalid document {$document_id}" );
  771 + $this->setResponse ( array ('status_code' => 1 ) );
  772 + return false;
903 } 773 }
904 -  
905 - return array('status_code'=>0); 774 +
  775 + $result = $document->delete ( $reason );
  776 + if (PEAR::isError ( $result )) {
  777 + $this->addError ( "Could not delete document {$document_id}" );
  778 + $this->setResponse ( array ('status_code' => 1 ) );
  779 + return false;
  780 + }
  781 + $this->setResponse ( array ('status_code' => 0 ) );
  782 + return true;
906 } 783 }
907 -  
908 - function get_client_policy($arr){  
909 - $policy_name=$arr['policy_name'];  
910 -  
911 - $config=KTConfig::getSingleton();  
912 -  
913 - $policy=array(  
914 - 'name'=>$policy_name,  
915 - 'value'=>serviceHelper::bool2str($config->get($policy_name)),  
916 - 'type'=>'boolean'  
917 - );  
918 -  
919 - $response['policy']=$policy;  
920 - $response['message']='Knowledgetree client policies retrieval succeeded.';  
921 - $response['status_code']=0;  
922 -  
923 - $this->setResponse($response); 784 +
  785 + private function update_document_metadata($session_id, $document_id, $metadata, $application, $sysdata = null) {
  786 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  787 + $this->addDebug ( 'update_document_metadata', 'entered update_document_metadata' );
  788 + $kt = &$this->KT;
  789 + $responseType = 'kt_document_detail';
  790 +
  791 + $document = &$kt->get_document_by_id ( $document_id );
  792 + if (PEAR::isError ( $document )) {
  793 + return array ('status_code' => 1, 'error' => 'Error getting document' );
  794 + }
  795 +
  796 + $result = $document->update_metadata ( $metadata );
  797 + if (PEAR::isError ( $result )) {
  798 + return array ('status_code' => 1, 'error' => 'Error updating metadata' );
  799 + }
  800 +
  801 + $result = $document->update_sysdata ( $sysdata );
  802 + if (PEAR::isError ( $result )) {
  803 + return array ('status_code' => 1, 'error' => 'Error update_sysdata' );
  804 + }
  805 +
  806 + return array ('status_code' => 0 );
  807 + }
  808 +
  809 + function get_client_policy($arr) {
  810 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  811 + $policy_name = $arr ['policy_name'];
  812 +
  813 + $config = KTConfig::getSingleton ();
  814 +
  815 + $policy = array ('name' => $policy_name, 'value' => serviceHelper::bool2str ( $config->get ( $policy_name ) ), 'type' => 'boolean' );
  816 +
  817 + $response ['policy'] = $policy;
  818 + $response ['message'] = 'Knowledgetree client policies retrieval succeeded.';
  819 + $response ['status_code'] = 0;
  820 +
  821 + $this->setResponse ( $response );
924 return true; 822 return true;
925 } 823 }
926 -  
927 -  
928 - function search($arr){  
929 - $kt=&$this->KT;  
930 -  
931 - $listing=processSearchExpression("(GeneralText contains \"".$arr['query']."\")");  
932 -  
933 - $result=$this->_processListing($listing, 'search', $arr);  
934 -  
935 - if(!count($result)) {  
936 - $result[]=array(  
937 - 'text'=>$this->xlate("No results found"),  
938 - 'id'=>($listing[$i]['item_type']=='F' ? $listing[$i]['item_type']."_" : "").$listing[$i]['id'],  
939 - 'leaf'=>true,  
940 - 'relevance'=>0,  
941 - 'qtip'=> $this->xlate("Please retry your search")  
942 - );  
943 - }else{  
944 - $result=array_slice($result, 0, 200); 824 +
  825 + function search($arr) {
  826 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  827 + $kt = &$this->KT;
  828 +
  829 + $listing = processSearchExpression ( "(GeneralText contains \"" . $arr ['query'] . "\")" );
  830 +
  831 + $result = $this->_processListing ( $listing, 'search', $arr );
  832 +
  833 + if (! count ( $result )) {
  834 + $result [] = array ('text' => $this->xlate ( "No results found" ), 'id' => ($listing [$i] ['item_type'] == 'F' ? $listing [$i] ['item_type'] . "_" : "") . $listing [$i] ['id'], 'leaf' => true, 'relevance' => 0, 'qtip' => $this->xlate ( "Please retry your search" ) );
  835 + } else {
  836 + $result = array_slice ( $result, 0, 200 );
945 } 837 }
946 - 838 +
947 //$this->setResponse($result); 839 //$this->setResponse($result);
948 - $this->setResponse(array('totalCount'=>count($listing), 'items'=>$result));  
949 - 840 + $this->setResponse ( array ('totalCount' => count ( $listing ), 'items' => $result ) );
  841 +
950 return true; 842 return true;
951 } 843 }
952 -  
953 -  
954 - public function update_metadata($arr){  
955 - $metadata=array();  
956 - $meta=$arr['metadata'];  
957 -  
958 - $this->addDebug('','Entered add_document_with_metadata');  
959 - $this->addDebug('metadata received',$meta);  
960 -  
961 - $special=array();  
962 -// foreach($apacked as $packed){  
963 -// foreach($packed as $key=>$val) {  
964 -// if(substr($val->name,0,2) != '__') {  
965 -// if(!is_array($metadata[$val->fieldset])) {  
966 -// $metadata[$val->fieldset]['fieldset']=$val->fieldset;  
967 -// $metadata[$val->fieldset]['fields']=array();  
968 -// }  
969 -// $metadata[$val->fieldset]['fields'][]=array(  
970 -// 'name'=>$val->name,  
971 -// 'value'=>$val->value  
972 -// );  
973 -// }else{  
974 -// $special[$val->name]=$val->value;  
975 -// }  
976 -// }  
977 -// } 844 +
  845 + public function update_metadata($arr) {
  846 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  847 + $metadata = array ();
  848 + $meta = $arr ['metadata'];
  849 +
  850 + $this->addDebug ( '', 'Entered add_document_with_metadata' );
  851 + $this->addDebug ( 'metadata received', $meta );
  852 +
  853 + $special = array ();
  854 + // foreach($apacked as $packed){
  855 + // foreach($packed as $key=>$val) {
  856 + // if(substr($val->name,0,2) != '__') {
  857 + // if(!is_array($metadata[$val->fieldset])) {
  858 + // $metadata[$val->fieldset]['fieldset']=$val->fieldset;
  859 + // $metadata[$val->fieldset]['fields']=array();
  860 + // }
  861 + // $metadata[$val->fieldset]['fields'][]=array(
  862 + // 'name'=>$val->name,
  863 + // 'value'=>$val->value
  864 + // );
  865 + // }else{
  866 + // $special[$val->name]=$val->value;
  867 + // }
  868 + // }
  869 + // }
  870 +
978 871
979 /** 872 /**
980 873
981 Fatal error: Cannot unset string offsets in on line 981 874 Fatal error: Cannot unset string offsets in on line 981
982 */ 875 */
  876 +
  877 + // foreach($meta as $item){
  878 + // $isSpecial=substr($item['name'],0,2)=='__';
  879 + // if($isSpecial){
  880 + // $special[$item['name']]=$item['value'];
  881 + // }else{
  882 + // $fieldSet=$item['fieldset'];
  883 + // unset($item['fieldset']);
  884 + // $metadata[$fieldSet]['fieldset']=$fieldSet;
  885 + // $metadata[$fieldSet]['fields'][]=$item;
  886 + // }
  887 + // }
  888 +
983 889
984 -// foreach($meta as $item){  
985 -// $isSpecial=substr($item['name'],0,2)=='__';  
986 -// if($isSpecial){  
987 -// $special[$item['name']]=$item['value'];  
988 -// }else{  
989 -// $fieldSet=$item['fieldset'];  
990 -// unset($item['fieldset']);  
991 -// $metadata[$fieldSet]['fieldset']=$fieldSet;  
992 -// $metadata[$fieldSet]['fields'][]=$item;  
993 -// }  
994 -// }  
995 -  
996 - $metadata=array();  
997 - $special=array();  
998 -  
999 - foreach($meta as $item){  
1000 - if(substr($item['name'],0,2)=='__'){  
1001 - $special[$item['name']]=$item['value'];  
1002 - }else{  
1003 - $metadata[$item['fieldset']]['fieldset']=$item['fieldset'];  
1004 - $metadata[$item['fieldset']]['fields'][]=array('name'=>$item['name'],'value'=>$item['value']); 890 + $metadata = array ();
  891 + $special = array ();
  892 +
  893 + foreach ( $meta as $item ) {
  894 + if (substr ( $item ['name'], 0, 2 ) == '__') {
  895 + $special [$item ['name']] = $item ['value'];
  896 + } else {
  897 + $metadata [$item ['fieldset']] ['fieldset'] = $item ['fieldset'];
  898 + $metadata [$item ['fieldset']] ['fields'] [] = array ('name' => $item ['name'], 'value' => $item ['value'] );
1005 } 899 }
1006 } 900 }
1007 901
  902 + $this->addDebug ( 'after processing', array ('metadata' => $metadata, 'special' => $special ) );
1008 903
  904 + $document_id = $arr ['document_id'];
1009 905
1010 - $this->addDebug('after processing',array('metadata'=>$metadata,'special'=>$special)); 906 + $update_result = $this->update_document_metadata ( $arr ['session_id'], $document_id, $metadata, $arr ['application'], array () );
  907 + $this->addDebug ( '', '$this->response= from update_document_metadata' );
1011 908
1012 - $document_id=$arr['document_id'];  
1013 -  
1014 - $update_result=$this->update_document_metadata($arr['session_id'], $document_id, $metadata, $arr['application'], array());  
1015 - $this->addDebug('','$this->response= from update_document_metadata');  
1016 -  
1017 - $status_code=$update_result['status_code'];  
1018 - if ($status_code != 0){  
1019 - $this->setResponse($update_result); 909 + $status_code = $update_result ['status_code'];
  910 + if ($status_code != 0) {
  911 + $this->setResponse ( $update_result );
1020 } 912 }
1021 -  
1022 - $kt=&$this->KT;  
1023 -  
1024 - if(!empty($special)) {  
1025 - if($document_id > 0) {  
1026 - $document=$kt->get_document_by_id($document_id);  
1027 -  
1028 - if(isset($special['__title'])) {  
1029 - $this->addDebug("Renaming to {$special['__title']}");  
1030 - $res=$document->rename($special['__title']);  
1031 - }  
1032 - }  
1033 - }  
1034 -  
1035 - $this->setResponse(array('status_code'=>0, 'document_id'=>$document_id));  
1036 - }  
1037 -  
1038 -  
1039 -  
1040 - function check_document_title($arr){  
1041 - $kt=&$this->KT;  
1042 -  
1043 - $folder=$kt->get_folder_by_id($arr['folder_id']);  
1044 - if(PEAR::isError($folder)) {  
1045 - $this->setResponse(array('status_code'=>1, 'reason'=>'No such folder'));  
1046 - return false;  
1047 - }  
1048 -  
1049 - $doc=$folder->get_document_by_name($arr['title']);  
1050 - if(PEAR::isError($doc)) {  
1051 - $this->setResponse(array('status_code'=>1, 'reason'=>'No document with that title '.$arr['title']));  
1052 - return false;  
1053 - }  
1054 -  
1055 - $this->setResponse(array('status_code'=>0));  
1056 - return true; 913 +
  914 + $kt = &$this->KT;
  915 +
  916 + if (! empty ( $special )) {
  917 + if ($document_id > 0) {
  918 + $document = $kt->get_document_by_id ( $document_id );
  919 +
  920 + if (isset ( $special ['__title'] )) {
  921 + $this->addDebug ( "Renaming to {$special['__title']}" );
  922 + $res = $document->rename ( $special ['__title'] );
  923 + }
  924 + }
  925 + }
  926 +
  927 + $this->setResponse ( array ('status_code' => 0, 'document_id' => $document_id ) );
1057 } 928 }
1058 -  
1059 -  
1060 - function cancel_checkout($params){  
1061 - $kt=&$this->KT;  
1062 -  
1063 - $document=&$kt->get_document_by_id($params['document_id']);  
1064 - if (PEAR::isError($document)){  
1065 - $this->setResponse(array('status_code'=>1, 'message'=>$document->getMessage()));  
1066 - return false;  
1067 - }  
1068 -  
1069 - $result=$document->undo_checkout($params['reason']);  
1070 - if (PEAR::isError($result)){  
1071 - $this->setResponse(array('status_code'=>1, 'message'=>$result->getMessage())); 929 +
  930 + function check_document_title($arr) {
  931 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  932 + $kt = &$this->KT;
  933 +
  934 + $folder = $kt->get_folder_by_id ( $arr ['folder_id'] );
  935 + if (PEAR::isError ( $folder )) {
  936 + $this->setResponse ( array ('status_code' => 1, 'reason' => 'No such folder' ) );
1072 return false; 937 return false;
1073 - }  
1074 - $response['status_code']=0;  
1075 - $this->setResponse($response);  
1076 - }  
1077 -  
1078 -  
1079 - public function get_users_groups($params){  
1080 - $kt=&$this->KT;  
1081 - $query=$params['query']; 938 + }
  939 +
  940 + $doc = $folder->get_document_by_name ( $arr ['title'] );
  941 + if (PEAR::isError ( $doc )) {
  942 + $this->setResponse ( array ('status_code' => 1, 'reason' => 'No document with that title ' . $arr ['title'] ) );
  943 + return false;
  944 + }
  945 +
  946 + $this->setResponse ( array ('status_code' => 0 ) );
  947 + return true;
  948 + }
  949 +
  950 + function cancel_checkout($params) {
  951 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  952 + $kt = &$this->KT;
  953 +
  954 + $document = &$kt->get_document_by_id ( $params ['document_id'] );
  955 + if (PEAR::isError ( $document )) {
  956 + $this->setResponse ( array ('status_code' => 1, 'message' => $document->getMessage () ) );
  957 + return false;
  958 + }
  959 +
  960 + $result = $document->undo_checkout ( $params ['reason'] );
  961 + if (PEAR::isError ( $result )) {
  962 + $this->setResponse ( array ('status_code' => 1, 'message' => $result->getMessage () ) );
  963 + return false;
  964 + }
  965 + $response ['status_code'] = 0;
  966 + $this->setResponse ( $response );
  967 + }
  968 +
  969 + function get_transaction_history($params) {
  970 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  971 + $kt = &$this->KT;
  972 +
  973 + $document = &$kt->get_document_by_id ( $params ['document_id'] );
  974 + if (PEAR::isError ( $document )) {
  975 + $this->setResponse ( array ('status_code' => 1, 'message' => $document->getMessage () ) );
  976 + return false;
  977 + }
  978 +
  979 + $versions = $document->get_version_history ();
  980 + $transactions = $document->get_transaction_history ();
  981 + $response ['status_code'] = 0;
  982 + $response ['transactions'] = $transactions;
  983 + $response ['versions'] = $versions;
  984 + $this->setResponse ( $response );
  985 + }
  986 +
  987 + public function get_users_groups($params) {
  988 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  989 + $kt = &$this->KT;
  990 + $query = $params ['query'];
1082 //$start=$params['start']; 991 //$start=$params['start'];
1083 //$page=$params['page']; 992 //$page=$params['page'];
  993 +
1084 994
1085 - $results=KTAPI_User::getList('name LIKE "%'.$query.'%" AND id>0');  
1086 - $returnArray=array();  
1087 - if (count($results) > 0){  
1088 - foreach ($results as $user){  
1089 - $returnArray[]=array('emailid'=>'u_'.$user->getId(), 'name'=> $user->getName(), 'to'=>preg_replace('/('.$query.')/i', '<b>${0}</b>', $user->getName())); 995 + $results = KTAPI_User::getList ( 'name LIKE "%' . $query . '%" AND id>0' );
  996 + $returnArray = array ();
  997 + if (count ( $results ) > 0) {
  998 + foreach ( $results as $user ) {
  999 + $returnArray [] = array ('emailid' => 'u_' . $user->getId (), 'name' => $user->getName (), 'to' => preg_replace ( '/(' . $query . ')/i', '<b>${0}</b>', $user->getName () ) );
1090 } 1000 }
1091 } 1001 }
1092 1002
1093 - $groups=KTAPI_Group::getList('name LIKE "%'.$query.'%"');  
1094 - if (count($groups) > 0){  
1095 - foreach ($groups as $group){  
1096 - $returnArray[]=array('emailid'=>'g_'.$group->getId(), 'name'=> $group->getName(), 'to'=>preg_replace('/('.$query.')/i', '<b>${0}</b>', $group->getName())); 1003 + $groups = KTAPI_Group::getList ( 'name LIKE "%' . $query . '%"' );
  1004 + if (count ( $groups ) > 0) {
  1005 + foreach ( $groups as $group ) {
  1006 + $returnArray [] = array ('emailid' => 'g_' . $group->getId (), 'name' => $group->getName (), 'to' => preg_replace ( '/(' . $query . ')/i', '<b>${0}</b>', $group->getName () ) );
1097 } 1007 }
1098 } 1008 }
1099 1009
1100 - $sendArray=array ('emails'=>$returnArray, 'metaData'=>array('count'=>count($finalArray), 'root'=>'emails', fields=>array('name', 'to', 'emailid')));  
1101 - $this->setResponse($sendArray); 1010 + $sendArray = array ('emails' => $returnArray, 'metaData' => array ('count' => count ( $finalArray ), 'root' => 'emails', fields => array ('name', 'to', 'emailid' ) ) );
  1011 + $this->setResponse ( $sendArray );
1102 return true; 1012 return true;
1103 } 1013 }
1104 -  
1105 1014
1106 - function send_email($params){  
1107 - $kt=&$this->KT; 1015 + function send_email($params) {
  1016 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  1017 + $kt = &$this->KT;
1108 1018
1109 - $message=$params['message'];  
1110 - $list=$params['users'];  
1111 - $list=explode(',', $list); 1019 + $message = $params ['message'];
  1020 + $list = $params ['users'];
  1021 + $list = explode ( ',', $list );
1112 1022
1113 - $recipientsList=array(); 1023 + $recipientsList = array ();
1114 1024
1115 - foreach ($list as $recipient){  
1116 - if (trim($recipient) != ''){ // check that value is present 1025 + foreach ( $list as $recipient ) {
  1026 + if (trim ( $recipient ) != '') { // check that value is present
1117 // if @ sign is present, signifies email address 1027 // if @ sign is present, signifies email address
1118 - if(strpos($recipient, '@') === false) {  
1119 - $recipient=trim($recipient);  
1120 - switch (substr($recipient, 0, 2)){  
1121 - case 'u_':  
1122 - $id=substr($recipient, 2);  
1123 - $user=KTAPI_User::getById($id);  
1124 - if ($user != null){  
1125 - $recipientsList[]=$user; 1028 + if (strpos ( $recipient, '@' ) === false) {
  1029 + $recipient = trim ( $recipient );
  1030 + switch (substr ( $recipient, 0, 2 )) {
  1031 + case 'u_' :
  1032 + $id = substr ( $recipient, 2 );
  1033 + $user = KTAPI_User::getById ( $id );
  1034 + if ($user != null) {
  1035 + $recipientsList [] = $user;
1126 } 1036 }
1127 break; 1037 break;
1128 - case 'g_':  
1129 - $id=substr($recipient, 2);  
1130 - $group=KTAPI_Group::getById($id); 1038 + case 'g_' :
  1039 + $id = substr ( $recipient, 2 );
  1040 + $group = KTAPI_Group::getById ( $id );
1131 if ($group != null) { 1041 if ($group != null) {
1132 - $recipientsList[]=$group; 1042 + $recipientsList [] = $group;
1133 } 1043 }
1134 break; 1044 break;
1135 } 1045 }
1136 - }else{ // Email - just add to list  
1137 - $recipientsList[]=trim($recipient); 1046 + } else { // Email - just add to list
  1047 + $recipientsList [] = trim ( $recipient );
1138 } 1048 }
1139 } 1049 }
1140 } 1050 }
1141 1051
1142 - $document=$kt->get_document_by_id($params['document']);  
1143 - if (count($recipientsList)==0) {  
1144 - $this->setResponse(array('status'=>'norecipients')); 1052 + $document = $kt->get_document_by_id ( $params ['document'] );
  1053 + if (count ( $recipientsList ) == 0) {
  1054 + $this->setResponse ( array ('status' => 'norecipients' ) );
1145 return false; 1055 return false;
1146 - }else{  
1147 - $result = $document->email($recipientsList, $message, TRUE); // true to attach document  
1148 - if (PEAR::isError($result)) {  
1149 - $this->setResponse(array('status'=>$result->getMessage()));;  
1150 - return false;  
1151 - }  
1152 - $this->setResponse(array('status'=>'documentemailed')); 1056 + } else {
  1057 + $result = $document->email ( $recipientsList, $message, TRUE ); // true to attach document
  1058 + if (PEAR::isError ( $result )) {
  1059 + $this->setResponse ( array ('status' => $result->getMessage () ) );
  1060 + ;
  1061 + return false;
  1062 + }
  1063 + $this->setResponse ( array ('status' => 'documentemailed' ) );
1153 } 1064 }
1154 return true; 1065 return true;
1155 } 1066 }
1156 -  
1157 -  
1158 - function is_latest_version($params){  
1159 - $kt=&$this->KT; 1067 +
  1068 + function is_latest_version($params) {
  1069 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  1070 + $kt = &$this->KT;
1160 1071
1161 - $documentId=$params['document_id'];  
1162 - $contentId=$params['content_id']; 1072 + $documentId = $params ['document_id'];
  1073 + $contentId = $params ['content_id'];
1163 1074
1164 - $result=$kt->is_latest_version($documentId, $contentId); 1075 + $result = $kt->is_latest_version ( $documentId, $contentId );
1165 1076
1166 - $this->setResponse($result); 1077 + $this->setResponse ( $result );
1167 return true; 1078 return true;
1168 } 1079 }
1169 1080
1170 - function check_permission($params){  
1171 - $kt=&$this->KT;  
1172 -  
1173 - $user=$kt->get_user();  
1174 - $document=$kt->get_document_by_id($params['document_id']);  
1175 - $folder=&$kt->get_folder_by_id($document->ktapi_folder->folderid);  
1176 - $folderDetail=$folder->get_detail();  
1177 - $permissions=$folderDetail['permissions'];  
1178 - if ($user->getId()==$document->document->getCheckedOutUserID()){ 1081 + function check_permission($params) {
  1082 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  1083 + $kt = &$this->KT;
  1084 +
  1085 + $user = $kt->get_user ();
  1086 + $document = $kt->get_document_by_id ( $params ['document_id'] );
  1087 + $folder = &$kt->get_folder_by_id ( $document->ktapi_folder->folderid );
  1088 + $folderDetail = $folder->get_detail ();
  1089 + $permissions = $folderDetail ['permissions'];
  1090 + if ($user->getId () == $document->document->getCheckedOutUserID ()) {
1179 $permissions .= 'E'; 1091 $permissions .= 'E';
1180 } 1092 }
1181 1093
1182 - $this->setResponse(array('status_code'=>0, 'permissions'=>$permissions)); 1094 + $this->setResponse ( array ('status_code' => 0, 'permissions' => $permissions ) );
1183 return true; 1095 return true;
1184 } 1096 }
1185 -  
1186 - function copydocument($params){  
1187 - $kt=&$this->KT;  
1188 -  
1189 - $response=$kt->copy_document($params['documentid'], $params['destfolderid'], $params['reason']);  
1190 - if ($response['status_code']==0) {  
1191 - $this->setResponse(array('status_code'=>0, 'status'=>'itemupdated', 'icon'=>'success', 'title'=>$this->xlate('Document Copied'), 'message'=>$this->xlate('Document has been successfully copied')));  
1192 - return true;  
1193 - }else{  
1194 - $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to copy document'), 'message'=>$this->xlate('Unable to copy document')));  
1195 - return false;  
1196 - }  
1197 - }  
1198 -  
1199 - function movedocument($params){  
1200 - $kt=$this->KT;  
1201 -  
1202 - $response=$kt->move_document($params['documentid'], $params['destfolderid'], $params['reason']);  
1203 - if ($response['status_code']==0) {  
1204 - $this->setResponse(array('status_code'=>0, 'status'=>'itemupdated', 'icon'=>'success', 'title'=>$this->xlate('Document Moved'), 'message'=>$this->xlate('Document has been successfully moved')));  
1205 - return true;  
1206 - }else{  
1207 - $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to move document'), 'message'=>$this->xlate('Unable to move document')));  
1208 - return false;  
1209 - }  
1210 -  
1211 - }  
1212 -  
1213 - function copyfolder($params){  
1214 - $kt=&$this->KT;  
1215 -  
1216 - $response=$kt->copy_folder($params['sourcefolderid'], $params['destfolderid'], $params['reason']);  
1217 - if ($response['status_code']==0) {  
1218 - $this->setResponse(array('status_code'=>0, 'status'=>'itemupdated', 'icon'=>'success', 'title'=>$this->xlate('Folder Copied'), 'message'=>$this->xlate('Folder has been successfully copied')));  
1219 - return true;  
1220 - }else{  
1221 - $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to copy folder'), 'message'=>$this->xlate('Unable to copy folder')));  
1222 - return false;  
1223 - }  
1224 -  
1225 - }  
1226 -  
1227 - function movefolder($params){  
1228 - $kt=&$this->KT;  
1229 -  
1230 - $response=$kt->move_folder($params['sourcefolderid'], $params['destfolderid'], $params['reason']);  
1231 - if ($response['status_code']==0) {  
1232 - $this->setResponse(array('status_code'=>0, 'status'=>'itemupdated', 'icon'=>'success', 'title'=>$this->xlate('Folder Moved'), 'message'=>$this->xlate('Folder has been successfully moved')));  
1233 - return true;  
1234 - }else{  
1235 - $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to move folder'), 'message'=>$this->xlate('Unable to move folder')));  
1236 - return false;  
1237 - }  
1238 - }  
1239 -  
1240 -  
1241 - function renamefolder($params){  
1242 - $kt=&$this->KT;  
1243 -  
1244 - $response=$kt->rename_folder($params['currentfolderid'], $params['newname']);  
1245 - if ($response['status_code']==0) {  
1246 - $this->setResponse(array('status_code'=>0, 'status'=>'folderupdated', 'icon'=>'success', 'title'=>$this->xlate('Folder Renamed'), 'message'=>$this->xlate('Folder has been successfully renamed')));  
1247 - return true;  
1248 - }else{  
1249 - $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to rename folder'), 'message'=>$this->xlate('Unable to rename folder')));  
1250 - return false;  
1251 - }  
1252 - }  
1253 -  
1254 - function addfolder($params) {  
1255 - $kt=&$this->KT;  
1256 - $this->addDebug('parameters',$params);  
1257 - $response=$kt->create_folder($params['currentfolderid'], $params['newname']);  
1258 - $this->setResponse($response); 1097 +
  1098 + function copydocument($params) {
  1099 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  1100 + $kt = &$this->KT;
  1101 +
  1102 + $response = $kt->copy_document ( $params ['documentid'], $params ['destfolderid'], $params ['reason'] );
  1103 + if ($response ['status_code'] == 0) {
  1104 + $this->setResponse ( array ('status_code' => 0, 'status' => 'itemupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Document Copied' ), 'message' => $this->xlate ( 'Document has been successfully copied' ) ) );
  1105 + return true;
  1106 + } else {
  1107 + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to copy document' ), 'message' => $this->xlate ( 'Unable to copy document' ) ) );
  1108 + return false;
  1109 + }
  1110 + }
  1111 +
  1112 + function movedocument($params) {
  1113 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  1114 + $kt = $this->KT;
  1115 +
  1116 + $response = $kt->move_document ( $params ['documentid'], $params ['destfolderid'], $params ['reason'] );
  1117 + if ($response ['status_code'] == 0) {
  1118 + $this->setResponse ( array ('status_code' => 0, 'status' => 'itemupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Document Moved' ), 'message' => $this->xlate ( 'Document has been successfully moved' ) ) );
  1119 + return true;
  1120 + } else {
  1121 + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to move document' ), 'message' => $this->xlate ( 'Unable to move document' ) ) );
  1122 + return false;
  1123 + }
  1124 +
  1125 + }
  1126 +
  1127 + function copyfolder($params) {
  1128 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  1129 + $kt = &$this->KT;
  1130 +
  1131 + $response = $kt->copy_folder ( $params ['sourcefolderid'], $params ['destfolderid'], $params ['reason'] );
  1132 + if ($response ['status_code'] == 0) {
  1133 + $this->setResponse ( array ('status_code' => 0, 'status' => 'itemupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Folder Copied' ), 'message' => $this->xlate ( 'Folder has been successfully copied' ) ) );
  1134 + return true;
  1135 + } else {
  1136 + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to copy folder' ), 'message' => $this->xlate ( 'Unable to copy folder' ) ) );
  1137 + return false;
  1138 + }
  1139 +
  1140 + }
  1141 +
  1142 + function movefolder($params) {
  1143 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  1144 + $kt = &$this->KT;
  1145 +
  1146 + $response = $kt->move_folder ( $params ['sourcefolderid'], $params ['destfolderid'], $params ['reason'] );
  1147 + if ($response ['status_code'] == 0) {
  1148 + $this->setResponse ( array ('status_code' => 0, 'status' => 'itemupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Folder Moved' ), 'message' => $this->xlate ( 'Folder has been successfully moved' ) ) );
  1149 + return true;
  1150 + } else {
  1151 + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to move folder' ), 'message' => $this->xlate ( 'Unable to move folder' ) ) );
  1152 + return false;
  1153 + }
  1154 + }
  1155 +
  1156 + function renamefolder($params) {
  1157 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  1158 + $kt = &$this->KT;
  1159 +
  1160 + $response = $kt->rename_folder ( $params ['currentfolderid'], $params ['newname'] );
  1161 + if ($response ['status_code'] == 0) {
  1162 + $this->setResponse ( array ('status_code' => 0, 'status' => 'folderupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Folder Renamed' ), 'message' => $this->xlate ( 'Folder has been successfully renamed' ) ) );
  1163 + return true;
  1164 + } else {
  1165 + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to rename folder' ), 'message' => $this->xlate ( 'Unable to rename folder' ) ) );
  1166 + return false;
  1167 + }
  1168 + }
  1169 +
  1170 + function addfolder($params) {
  1171 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  1172 + $kt = &$this->KT;
  1173 + $this->addDebug ( 'parameters', $params );
  1174 + $response = $kt->create_folder ( $params ['currentfolderid'], $params ['newname'] );
  1175 + $this->setResponse ( $response );
1259 return true; 1176 return true;
1260 - }  
1261 -  
1262 - function deletefolder($params){  
1263 - $kt=&$this->KT;  
1264 -  
1265 - $response=$kt->delete_folder($params['folderid'], $params['reason']);  
1266 - if ($response['status_code']==0) {  
1267 - $this->setResponse(array('status_code'=>0, 'status'=>'folderdeleted', 'icon'=>'success', 'title'=>$this->xlate('Folder Deleted'), 'message'=>$this->xlate('Folder has been successfully deleted')));  
1268 - return true;  
1269 - }else{  
1270 - $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to delete folder'), 'message'=>$this->xlate('Unable to delete folder')));  
1271 - return false;  
1272 - }  
1273 - }  
1274 -  
1275 - function candeletefolder($arr){  
1276 - $kt=&$this->KT;  
1277 -  
1278 - $folder=&$kt->get_folder_by_id($arr['folderid']);  
1279 - if (PEAR::isError($folder)){  
1280 - $this->setResponse('error 1');  
1281 - return false;  
1282 - }  
1283 -  
1284 - $listing=$folder->get_listing(1, 'DF');  
1285 - if (count($listing)==0) {  
1286 - $this->setResponse(array('status_code'=>0, 'candelete'=>TRUE));  
1287 - return true;  
1288 - }else{  
1289 - $this->setResponse(array('status_code'=>0, 'candelete'=>FALSE));  
1290 - return true;  
1291 - }  
1292 - } 1177 + }
  1178 +
  1179 + function deletefolder($params) {
  1180 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  1181 + $kt = &$this->KT;
  1182 +
  1183 + $response = $kt->delete_folder ( $params ['folderid'], $params ['reason'] );
  1184 + if ($response ['status_code'] == 0) {
  1185 + $this->setResponse ( array ('status_code' => 0, 'status' => 'folderdeleted', 'icon' => 'success', 'title' => $this->xlate ( 'Folder Deleted' ), 'message' => $this->xlate ( 'Folder has been successfully deleted' ) ) );
  1186 + return true;
  1187 + } else {
  1188 + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to delete folder' ), 'message' => $this->xlate ( 'Unable to delete folder' ) ) );
  1189 + return false;
  1190 + }
  1191 + }
  1192 +
  1193 + function candeletefolder($arr) {
  1194 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
  1195 + $kt = &$this->KT;
  1196 +
  1197 + $folder = &$kt->get_folder_by_id ( $arr ['folderid'] );
  1198 + if (PEAR::isError ( $folder )) {
  1199 + $this->setResponse ( 'error 1' );
  1200 + return false;
  1201 + }
  1202 +
  1203 + $listing = $folder->get_listing ( 1, 'DF' );
  1204 + if (count ( $listing ) == 0) {
  1205 + $this->setResponse ( array ('status_code' => 0, 'candelete' => TRUE ) );
  1206 + return true;
  1207 + } else {
  1208 + $this->setResponse ( array ('status_code' => 0, 'candelete' => FALSE ) );
  1209 + return true;
  1210 + }
  1211 + }
1293 } 1212 }
1294 ?> 1213 ?>
1295 \ No newline at end of file 1214 \ No newline at end of file
webservice/clienttools/services/0.9/server.php
1 <?php 1 <?php
2 class server extends client_service { 2 class server extends client_service {
3 public function status(){ 3 public function status(){
  4 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
4 $this->setResponse(array('online'=>true)); 5 $this->setResponse(array('online'=>true));
5 } 6 }
6 7
7 public function ping(){ 8 public function ping(){
  9 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
8 $this->addResponse('pong',time()); 10 $this->addResponse('pong',time());
9 } 11 }
10 12
11 public function getToken(){ 13 public function getToken(){
  14 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
12 15
13 } 16 }
14 17
15 public function phpInfo(){ 18 public function phpInfo(){
  19 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
16 ob_start(); 20 ob_start();
17 phpinfo(); 21 phpinfo();
18 $this->addResponse('phpinfo',ob_get_clean()); 22 $this->addResponse('phpinfo',ob_get_clean());
webservice/clienttools/standardservices/system.php
1 <?php 1 <?php
2 class system extends client_service{ 2 class system extends client_service{
3 public function checkVersion(){ 3 public function checkVersion(){
  4 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
4 global $default; 5 global $default;
5 $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']); 6 $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']);
6 $versions=$this->handler->getServerVersions(); 7 $versions=$this->handler->getServerVersions();
@@ -19,11 +20,14 @@ class system extends client_service{ @@ -19,11 +20,14 @@ class system extends client_service{
19 20
20 ); 21 );
21 $this->setResponse($ret); 22 $this->setResponse($ret);
  23 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Exit Function');
22 return true; 24 return true;
23 } 25 }
24 26
25 public function jsondecode($params){ 27 public function jsondecode($params){
  28 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Enter Function');
26 $this->setResponse(@json_decode(trim($params['code']))); 29 $this->setResponse(@json_decode(trim($params['code'])));
  30 + $this->logTrace(__CLASS__.'::'.__METHOD__.'('.__FILE__.' '.__LINE__,'Exit Function');
27 } 31 }
28 } 32 }
29 33