Commit bddd8abfb7c1e194d3e79680c7f407f87a18a98a

Authored by Megan Watson
2 parents 538cf2ce 7f63ca76

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

ktapi/KTAPIDocument.inc.php
@@ -1929,7 +1929,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -1929,7 +1929,7 @@ class KTAPI_Document extends KTAPI_FolderItem
1929 $this->clearCache(); 1929 $this->clearCache();
1930 1930
1931 $config = KTConfig::getSingleton(); 1931 $config = KTConfig::getSingleton();
1932 - $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION); 1932 + $wsversion = $config->get('webservice/version', $this->ktapi->webserviceVersion);
1933 1933
1934 $detail = array(); 1934 $detail = array();
1935 $document = $this->document; 1935 $document = $this->document;
@@ -2230,7 +2230,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -2230,7 +2230,7 @@ class KTAPI_Document extends KTAPI_FolderItem
2230 } 2230 }
2231 2231
2232 $config = KTConfig::getSingleton(); 2232 $config = KTConfig::getSingleton();
2233 - $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION); 2233 + $wsversion = $config->get('webservice/version', $this->ktapi->webserviceVersion);
2234 foreach($transactions as $key=>$transaction) 2234 foreach($transactions as $key=>$transaction)
2235 { 2235 {
2236 $transactions[$key]['version'] = (float) $transaction['version']; 2236 $transactions[$key]['version'] = (float) $transaction['version'];
@@ -2251,7 +2251,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -2251,7 +2251,7 @@ class KTAPI_Document extends KTAPI_FolderItem
2251 $metadata_versions = KTDocumentMetadataVersion::getByDocument($this->document); 2251 $metadata_versions = KTDocumentMetadataVersion::getByDocument($this->document);
2252 2252
2253 $config = KTConfig::getSingleton(); 2253 $config = KTConfig::getSingleton();
2254 - $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION); 2254 + $wsversion = $config->get('webservice/version', $this->ktapi->webserviceVersion);
2255 2255
2256 $versions = array(); 2256 $versions = array();
2257 foreach ($metadata_versions as $version) 2257 foreach ($metadata_versions as $version)
ktapi/KTAPIFolder.inc.php
@@ -184,7 +184,7 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -184,7 +184,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
184 $this->clearCache(); 184 $this->clearCache();
185 185
186 $config = KTConfig::getSingleton(); 186 $config = KTConfig::getSingleton();
187 - $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION); 187 + $wsversion = $config->get('webservice/version', $this->ktapi->webserviceVersion);
188 188
189 $detail = array( 189 $detail = array(
190 'id'=>(int) $this->folderid, 190 'id'=>(int) $this->folderid,
@@ -548,7 +548,7 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -548,7 +548,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
548 548
549 $config = KTConfig::getSingleton(); 549 $config = KTConfig::getSingleton();
550 550
551 - $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION); 551 + $wsversion = $config->get('webservice/version', $this->ktapi->webserviceVersion);
552 552
553 $user = $this->ktapi->get_user(); 553 $user = $this->ktapi->get_user();
554 554
@@ -841,7 +841,7 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -841,7 +841,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
841 841
842 $config = KTConfig::getSingleton(); 842 $config = KTConfig::getSingleton();
843 843
844 - $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION); 844 + $wsversion = $config->get('webservice/version', $this->ktapi->webserviceVersion);
845 845
846 $user = $this->ktapi->get_user(); 846 $user = $this->ktapi->get_user();
847 847
@@ -1471,7 +1471,7 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -1471,7 +1471,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
1471 } 1471 }
1472 1472
1473 $config = KTConfig::getSingleton(); 1473 $config = KTConfig::getSingleton();
1474 - $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION); 1474 + $wsversion = $config->get('webservice/version', $this->ktapi->webserviceVersion);
1475 foreach($transactions as $key=>$transaction) 1475 foreach($transactions as $key=>$transaction)
1476 { 1476 {
1477 $transactions[$key]['version'] = (float) $transaction['version']; 1477 $transactions[$key]['version'] = (float) $transaction['version'];
ktapi/ktapi.inc.php
@@ -176,10 +176,18 @@ class KTAPI @@ -176,10 +176,18 @@ class KTAPI
176 protected $version = 3; 176 protected $version = 3;
177 177
178 private $esig_enabled; 178 private $esig_enabled;
  179 +
  180 + public $webserviceVersion;
179 181
180 - public function KTAPI() 182 + public function KTAPI($webserviceVersion = '')
181 { 183 {
182 $this->esig_enabled = $this->electronic_sig_enabled(); 184 $this->esig_enabled = $this->electronic_sig_enabled();
  185 +
  186 + if ($webserviceVersion == '') {
  187 + $this->webserviceVersion = LATEST_WEBSERVICE_VERSION;
  188 + } else {
  189 + $this->webserviceVersion = $webserviceVersion;
  190 + }
183 } 191 }
184 192
185 /** 193 /**
webservice/clienttools/comms.php
@@ -65,7 +65,7 @@ include_once('clienttools_syslog.php'); @@ -65,7 +65,7 @@ include_once('clienttools_syslog.php');
65 Clienttools_Syslog::logTrace('--','--','======================================================================== TRANSACTION START'); 65 Clienttools_Syslog::logTrace('--','--','======================================================================== TRANSACTION START');
66 66
67 //Instantiate base classes 67 //Instantiate base classes
68 -$KT = new KTAPI(); 68 +$KT = new KTAPI(3);
69 $RET=new jsonResponseObject(); 69 $RET=new jsonResponseObject();
70 if($_GET['datasource'])$RET->isDataSource=true; 70 if($_GET['datasource'])$RET->isDataSource=true;
71 71
webservice/clienttools/services/0.9.2/auth.php 0 → 100644
  1 +<?php
  2 +
  3 +class auth extends client_service {
  4 +
  5 + public function login(){
  6 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  7 + $params=$this->AuthInfo;
  8 +
  9 + $username=$params['user'];
  10 + $passhash=$params['passhash'];
  11 + $token=$params['token'];
  12 + $app_type=$params['appType'];
  13 + $session_id=$params['session'];
  14 + $ip=$_SERVER['REMOTE_ADDR'];
  15 + $language=isset($params['language'])?$params['language']:'en';
  16 +
  17 + $this->Response->setDebug('parameters',$params);
  18 +
  19 + setcookie("kt_language", $language, 2147483647, '/');
  20 +
  21 + $kt =& $this->KT;
  22 +
  23 + if ($username != 'admin') {
  24 + //$this->addDebug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@','');
  25 +
  26 + try{
  27 + if(class_exists('BaobabKeyUtil')){
  28 + if (!BaobabKeyUtil::checkIfLicensed(true)) {
  29 + $this->setResponse(array('authenticated'=> false, 'message'=> 'license_expired'));
  30 + $this->addError('Licence Expired');
  31 + return false;
  32 + }
  33 + }else{
  34 + $this->addError('Licence Utility could not be loaded. Appears to be a Community version.');
  35 + $this->setResponse(array('authenticated'=> false, 'message'=> 'Licence Utility could not be loaded. Appears to be a Community version.'));
  36 + return false;
  37 + }
  38 + }catch(Exception $e){
  39 + $this->addError('could not execute BaobabKeyUtil::checkIfLicensed');
  40 + $this->setResponse(array('authenticated'=> false, 'message'=> 'BaobabKeyUtil::checkIfLicensed error'));
  41 + return;
  42 + }
  43 + }
  44 +
  45 + $user=$kt->get_user_object_by_username($username);
  46 + if(!PEAR::isError($user)){
  47 + $password=$user->getPassword();
  48 + $localPassHash=md5($password.$token);
  49 + if($localPassHash==$passhash){
  50 + $session=new stdClass();
  51 + $this->Response->setDebug('trying to start session with',array('username'=>$username,'password'=>$password));
  52 + $session = $kt->start_session($username, $params['pass'],NULL,$app_type);
  53 + if(!PEAR::isError($session)){
  54 + $this->Response->setStatus('session_id',$session->get_session());
  55 + }else{
  56 + $this->setResponse(array('authenticated'=> false, 'message'=> 'Invalid username and/or password.'));
  57 + $this->addDebug('failed login',print_r($session,true));
  58 + $this->addError('Unknown Login Error');
  59 + return false;
  60 + }
  61 + }else{
  62 + $this->addError('Incorrect Credentials');
  63 + //throw new Exception('Incorrect Credentials');
  64 + return false;
  65 + }
  66 + }else{
  67 + $this->addError('Incorrect Credentials');
  68 + //throw new Exception('Unrecognized User');
  69 + return false;
  70 + }
  71 + return true;
  72 + }
  73 +
  74 + public function japiLogin(){
  75 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  76 + global $default;
  77 +
  78 + $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']);
  79 + $ret=array(
  80 + 'fullName' =>PEAR::isError($user)?'':$user->getName()
  81 + );
  82 + $this->setResponse($ret);
  83 + return true;
  84 + }
  85 +
  86 + public function pickup_session(){
  87 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  88 + $params=$this->AuthInfo;
  89 + $app_type=$params['appType'];
  90 + $session_id=$params['session'];
  91 + $ip=$_SERVER['REMOTE_ADDR'];
  92 +
  93 + $session = $this->KT->get_active_session($session_id, $ip, $app_type);
  94 +
  95 + if (PEAR::isError($session)){
  96 + return false;
  97 + }
  98 + $this->Response->setStatus('session_id',$session->get_session());
  99 + return true;
  100 + }
  101 +
  102 +
  103 + public function ping(){
  104 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  105 + global $default;
  106 + $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']);
  107 + $versions=$this->handler->getServerVersions();
  108 + $bestVer=$versions[count($versions)-1];
  109 + $clientVer=$this->handler->getVersion();
  110 + $ret=array(
  111 + 'response' =>'pong',
  112 + 'loginLocation' => '/index.html',
  113 + 'versionok' =>in_array($clientVer,$versions),
  114 + 'fullName' =>PEAR::isError($user)?'':$user->getName(),
  115 + 'serverVersions' =>$versions,
  116 + 'serverBestVersion' =>$bestVer,
  117 + 'clientVersion' =>$clientVer,
  118 + 'canUpgradeClient' =>($clientVer<$bestVer?true:false),
  119 + 'canUpgradeServer' =>($clientVer>$bestVer?true:false)
  120 +
  121 + );
  122 + $this->setResponse($ret);
  123 + return true;
  124 + }
  125 +
  126 + function logout($params){
  127 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  128 + $params=$this->AuthInfo;
  129 + $app_type=$params['appType'];
  130 + $session_id=$params['session'];
  131 + $ip=$_SERVER['REMOTE_ADDR'];
  132 +
  133 + $session=$this->KT->get_session();
  134 + $this->logInfo((__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((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Logout Session Object (To Logout)',$session);
  140 +
  141 + if (PEAR::isError($session)){
  142 + return false;
  143 + }
  144 +
  145 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Proceeding With Logout');
  146 + $newSessId=md5(session_id());
  147 + $session->logout();
  148 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'KTAPI session logout requested');
  149 + session_id($newSessId);
  150 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'New SessionID Requested from PHP (Redundant Security)['.session_id().']');
  151 + $this->Response->setStatus('session_id',$newSessId);
  152 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'New SessionID set in response status ['.$newSessId.']');
  153 + $this->setResponse(array('logout'=>true));
  154 + session_destroy();
  155 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'PHP Session Destroyed');
  156 + return true;
  157 + }
  158 +
  159 +}
  160 +
  161 +?>
0 \ No newline at end of file 162 \ No newline at end of file
webservice/clienttools/services/0.9.2/kt.php 0 → 100644
  1 +<?php
  2 +class kt extends client_service {
  3 +
  4 + /**
  5 + * Get Supported (?) Languages
  6 + *
  7 + * returns array containing languages, count, & defaultlanguage
  8 + *
  9 + */
  10 + function get_languages($passthru = false) {
  11 + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' );
  12 + global $default;
  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 + if($sLang=='en') $languages [] = array ('isoCode' => $sLang, 'language' => $aLanguageNames [$sLang] );
  21 + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), "Removing Language {$aLanguageNames[$sLang]} from the list because Language Support not Ready." );
  22 +
  23 + }
  24 + }
  25 + $response = array ('languages' => $languages, 'count' => count ( $languages ), 'defaultLanguage' => $default->defaultLanguage );
  26 + if (is_bool ( $passthru ))
  27 + if ($passthru)
  28 + return $response;
  29 + $this->setResponse ( $response );
  30 + }
  31 +
  32 + function get_rootfolder_detail($params) {
  33 + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' );
  34 + $params ['folderId'] = '1';
  35 + $this->get_folder_detail ( $params );
  36 + }
  37 +
  38 + function get_folder_detail($params) {
  39 + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' );
  40 + if (isset ( $params ['node'] ) && ! isset ( $params ['folderId'] )) {
  41 + $params ['node'] = split ( '_', $params ['node'] );
  42 + $params ['folderId'] = $params ['node'] [1];
  43 + }
  44 + $kt = &$this->KT;
  45 +
  46 + $folder = &$kt->get_folder_by_id ( $params ['folderId'] );
  47 + if (PEAR::isError ( $folder )) {
  48 + $this->setError ( "Could not get folder by Id: {$params['folderId']}" );
  49 + $this->setDebug ( 'FolderError', array ('kt' => $kt, 'folder' => $folder ) );
  50 + return false;
  51 + }
  52 +
  53 + $detail = $folder->get_detail ();
  54 + if (PEAR::isError ( $detail )) {
  55 + $this->setResponse ( "detail error {$params['node']}" );
  56 + return false;
  57 + }
  58 +
  59 + if (strtolower ( $detail ['folder_name'] ) == 'root folder') {
  60 + $detail ['folder_name'] = 'KnowledgeTree';
  61 + }
  62 +
  63 + $qtip .= $this->xlate ( 'Folder name' ) . ": {$detail['folder_name']}<br>";
  64 + $class = 'folder';
  65 +
  66 + $permissions = $detail ['permissions'];
  67 + $perms = '';
  68 + $canWrite = false;
  69 +
  70 + for($j = 0; $j < strlen ( $permissions ); $j ++) {
  71 + switch (strtoupper ( $permissions {$j} )) {
  72 + case 'W' :
  73 + $canWrite = true;
  74 + $perms .= $this->xlate ( 'write, ' );
  75 + break;
  76 + case 'R' :
  77 + $perms .= $this->xlate ( 'read, ' );
  78 + break;
  79 + case 'A' :
  80 + $perms .= $this->xlate ( 'add folder, ' );
  81 + break;
  82 + }
  83 + }
  84 +
  85 + if (strlen ( $perms ) > 2) {
  86 + $perms = substr ( $perms, 0, strlen ( $perms ) - 2 );
  87 + }
  88 +
  89 + $qtip .= $this->xlate ( 'Permissions:' ) . " {$perms}<br>";
  90 + $qtip .= $canWrite ? $this->xlate ( 'You may add content to this folder' ) : $this->xlate ( 'You may not add content to this folder' );
  91 +
  92 + $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 );
  93 +
  94 + $this->setResponse ( $result );
  95 + return true;
  96 + }
  97 +
  98 + function get_checkedout_documents_list($params) {
  99 + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' );
  100 + $kt = &$this->KT;
  101 +
  102 +
  103 + $params ['control'] = 'F_';
  104 + $params ['node'] = substr ( $params ['node'], strlen ( $params ['control'] ) );
  105 +
  106 + $folder = &$kt->get_folder_by_id ( $params ['node'] );
  107 + if (! $this->checkPearError ( $folder, "[error 1] Folder Not Found: {$params['control']}{$params['node']}", '', array () ))
  108 + return false;
  109 +
  110 + $types = (isset ( $params ['types'] ) ? $params ['types'] : 'D');
  111 + $listing = $folder->get_listing ( 1, $types );
  112 + foreach ( $listing as $item ) {
  113 + if ($item['checked_out_by'] == $params['user'])
  114 + {
  115 + $result[] = array ('text' => htmlspecialchars ( $item ['title'] ), 'id' => $item ['id'], 'filename' => $item ['filename']);
  116 + }
  117 + }
  118 +
  119 + $this->setResponse ( $result );
  120 + return true;
  121 + }
  122 +
  123 + function get_folder_contents($params) {
  124 + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' );
  125 + $kt = &$this->KT;
  126 +
  127 + $params ['control'] = 'F_';
  128 + $params ['node'] = substr ( $params ['node'], strlen ( $params ['control'] ) );
  129 +
  130 + $folder = &$kt->get_folder_by_id ( $params ['node'] );
  131 + if (! $this->checkPearError ( $folder, "[error 1] Folder Not Found: {$params['control']}{$params['node']}", '', array () ))
  132 + return false;
  133 +
  134 + $types = (isset ( $params ['types'] ) ? $params ['types'] : 'DF');
  135 + $listing = $folder->get_listing ( 1, $types );
  136 + $result = $this->_processListing ( $listing, 'folderContents', $params );
  137 +
  138 + $this->setResponse ( $result );
  139 + return true;
  140 + }
  141 +
  142 + /**
  143 + * Returns the contents of a folder formatted for a grid view.
  144 + *
  145 + * @param array $arr
  146 + * @return array
  147 + */
  148 + function get_folder_contents_for_grid($arr) {
  149 + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' );
  150 + $kt = &$this->KT;
  151 +
  152 + $arr ['control'] = 'F_';
  153 + $arr ['node'] = substr ( $arr ['node'], strlen ( $arr ['control'] ) );
  154 +
  155 + $folder = &$kt->get_folder_by_id ( $arr ['node'] );
  156 + if (PEAR::isError ( $folder )) {
  157 + echo '<pre>' . print_r ( $arr, true ) . '</pre>';
  158 + $this->addError ( 'Folder Not found' );
  159 + return false;
  160 + }
  161 +
  162 + $folder->addFolderToUserHistory();
  163 +
  164 + $types = (isset ( $arr ['types'] ) ? $arr ['types'] : 'DFS');
  165 +
  166 + $listing = $folder->get_listing ( 1, $types );
  167 +
  168 + $result = $this->_processListing ( $listing, 'grid', $arr );
  169 +
  170 + $this->setResponse ( array ('totalCount' => count ( $listing ), 'items' => $result ) );
  171 +
  172 + return true;
  173 + }
  174 +
  175 + private function _processListing($listing, $type, $arr) {
  176 + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' );
  177 + $result = array ();
  178 + $methodToIncludeItem = '_processItemInclusion_' . $type;
  179 +
  180 + foreach ( $listing as $item ) {
  181 + $item['filesize_bytes']=($item['filesize']+0);
  182 + $this->logInfo('Listing Detail:',$item);
  183 + $this->addDebug('Listing Detail:',$item);
  184 + /* Trying to fix folder sizes */
  185 + if ($item ['filesize'] <= 0) {
  186 + $item ['filesize']='';
  187 + if($item['item_type']=='D')$item ['filesize'] =serviceHelper::size_readable ( 0 );
  188 + } else {
  189 + $item ['filesize'] = serviceHelper::size_readable ( $item ['filesize'] );
  190 +// $item ['filesize'] = serviceHelper::size_kb ( $item ['filesize'] ); //To Fix Column Sort Issue
  191 + }
  192 +
  193 + $filename = $item ['filename'];
  194 + $itemType = $item ['item_type'];
  195 +
  196 + $includeMe = true;
  197 + $qtip = '';
  198 + $canWrite = false;
  199 + $immutable = false;
  200 + $permissions = $item ['permissions'];
  201 + $perms = '';
  202 +
  203 +
  204 + for($j = 0; $j < strlen ( $permissions ); $j ++) {
  205 + switch (strtoupper ( $permissions {$j} )) {
  206 + case 'W' :
  207 + $canWrite = true;
  208 + $perms .= $this->xlate ( 'write, ' );
  209 + break;
  210 + case 'R' :
  211 + $perms .= $this->xlate ( 'read, ' );
  212 + break;
  213 + case 'A' :
  214 + $perms .= $this->xlate ( 'add folder, ' );
  215 + break;
  216 + }
  217 + }
  218 +
  219 + if (strlen ( $perms ) > 2) {
  220 + $perms = substr ( $perms, 0, strlen ( $perms ) - 2 );
  221 + }
  222 +
  223 + // This is done here because a shortcut can be a document or folder
  224 + switch ($itemType)
  225 + {
  226 + case 'F': $docOrFolder = 'F'; break;
  227 + case 'D': $docOrFolder = 'D'; break;
  228 + case 'S':
  229 + if (array_key_exists('linked_folder_id', $item)) {
  230 + $docOrFolder = 'F';
  231 + } else {
  232 + $docOrFolder = 'D';
  233 + }
  234 + break;
  235 + }
  236 +
  237 + if ($docOrFolder == 'F') {
  238 + $qtip .= $this->xlate ( 'Folder name' ) . ": {$filename}<br>";
  239 +
  240 + if ($itemType == 'S') {
  241 + $class = 'folder_shortcut';
  242 + } else {
  243 + $class = 'folder';
  244 + }
  245 +
  246 + $qtip .= $this->xlate ( 'Permissions:' ) . " {$perms}<br>";
  247 + $qtip .= $canWrite ? $this->xlate ( 'You may add content to this folder' ) : $this->xlate ( 'You may not add content to this folder' );
  248 + }
  249 +
  250 + //documents
  251 + else {
  252 + $qtip = '';
  253 + $extpos = strrpos ( $filename, '.' );
  254 +
  255 + if ($extpos === false) {
  256 + $class = 'file-unknown';
  257 + } else {
  258 + $ext = substr ( $filename, $extpos ); // Get Extension including the dot
  259 + $class = 'file-' . substr ( $filename, $extpos + 1 ); // Get Extension without the dot
  260 + }
  261 +
  262 + if ($itemType == 'S') {
  263 + $class .= '_shortcut';
  264 + }
  265 +
  266 +
  267 + $extensions = explode ( ',', $arr ['extensions'] );
  268 + if (! in_array ( strtolower ( $ext ), $extensions ) && ! in_array ( '*', $extensions )) {
  269 + $includeMe = false;
  270 + } else {
  271 + $qtip .= $this->xlate ( 'Filename' ) . ": {$filename}<br>";
  272 + $qtip .= $this->xlate ( 'File Size' ) . ": " . serviceHelper::fsize_desc ( $item ['filesize'] ) . "<br>";
  273 + $qtip .= $this->xlate ( 'Modified' ) . ": {$item['modified_date']}<br>";
  274 + $qtip .= $this->xlate ( 'Owner' ) . ": {$item['created_by']}<br>";
  275 + $qtip .= $this->xlate ( 'Version' ) . ": {$item['version']}<br>";
  276 + if (serviceHelper::bool2str ( strtolower ( $item ['is_immutable'] ) ) == 'true') {
  277 + $canWrite = false;
  278 + $immutable = true;
  279 + }
  280 +
  281 + if ($immutable) {
  282 + $qtip .= $this->xlate ( 'Status: Immutable' ) . '<br>';
  283 + } else if (strtolower ( $item ['checked_out_by'] ) != 'n/a' && ($item ['checked_out_by'] != '')) {
  284 + $qtip .= $this->xlate ( 'Status: Checked out by' ) . " {$item['checked_out_by']}<br>";
  285 + } else {
  286 + $qtip .= $this->xlate ( 'Status: Available' ) . '<br>';
  287 + }
  288 + $qtip .= $this->xlate ( 'Permissions:' ) . " {$perms}<br>";
  289 +
  290 + if ($immutable) {
  291 + $qtip .= $this->xlate ( 'This document is not editable' );
  292 + } else if ($canWrite) {
  293 + $qtip .= $this->xlate ( 'You may edit this document' );
  294 + } else {
  295 + $qtip .= $this->xlate ( 'This document is not editable' );
  296 + }
  297 + }
  298 + } //end of if for files
  299 + if ($includeMe) {
  300 + $result [] = $this->$methodToIncludeItem ( $item, $class, $qtip );
  301 + }
  302 + }
  303 + return $result;
  304 + }
  305 +
  306 + private function _processItemInclusion_folderContents($item, $class, $qtip) {
  307 + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' );
  308 + 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, 'is_immutable' => $item ['is_immutable'] );
  309 + }
  310 +
  311 + private function _processItemInclusion_search($item, $class, $qtip) {
  312 + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' );
  313 + if ($item ['filesize'] == 'n/a') {
  314 + $item ['filesize'] = - 1;
  315 + }
  316 + 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'], 'is_immutable' => $item ['is_immutable'], 'folder_id' => $item['folder_id'] );
  317 + }
  318 +
  319 + private function _processItemInclusion_grid($item, $class, $qtip) {
  320 + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' );
  321 + //var_dump($item);
  322 +
  323 +
  324 + if ($item ['filesize'] == 'n/a') {
  325 + $item ['filesize'] = - 1;
  326 + }
  327 +
  328 + if (array_key_exists('linked_folder_id', $item)) {
  329 + $linkedId = 'F_'.$item['linked_folder_id'];
  330 + } else {
  331 + $linkedId = 'D_'.$item['linked_document_id'];
  332 + }
  333 +
  334 +
  335 + 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'], 'filesize_bytes' => $item ['filesize_bytes'], 'modified' => $item ['modified_date'], 'checked_out_by' => $item ['checked_out_by'], 'version' => $item ['version'], 'is_immutable' => $item ['is_immutable'], 'linked_item'=>$linkedId );
  336 + }
  337 +
  338 + public function get_metadata($params) {
  339 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  340 + $kt = &$this->KT;
  341 +
  342 + if (substr ( $params ['document_id'], 0, 2 ) == 'D_') {
  343 + $params ['document_id'] = substr ( $params ['document_id'], 2 );
  344 + }
  345 +
  346 + $document_id = ( int ) $params ['document_id'];
  347 + if ($document_id > 0) {
  348 + $document = $kt->get_document_by_id ( $params ['document_id'] );
  349 + $detail = $document->get_metadata ();
  350 + $document_detail = $document->get_detail ();
  351 + $title = $document_detail ['title'];
  352 + $document_type = $document_detail ['document_type'];
  353 +
  354 + $document->addDocumentToUserHistory(); /* Added by Tohir */
  355 +
  356 + } else {
  357 + if (isset ( $params ['document_type'] )) {
  358 + $document_type = $params ['document_type'];
  359 + } else {
  360 + $document_type = 'Default';
  361 + }
  362 + $detail = $kt->get_document_type_metadata ( $document_type );
  363 + $title = "";
  364 + }
  365 +
  366 + $result = array ();
  367 + $items = array ();
  368 + $index = 0;
  369 + $items [] = array ("name" => "__title", "index" => 0, "value" => $title, "control_type" => "string" );
  370 +
  371 + // Commented out for timebeing - will be used by 'Save in Format'
  372 +
  373 +
  374 + if (isset ( $params ['extensions'] )) {
  375 +
  376 + $fileParts = pathinfo ( $document_detail ['filename'] );
  377 +
  378 + $items [] = array ("name" => "__document_extension", "index" => 0, "value" => strtolower ( $fileParts ['extension'] ), "control_type" => "lookup", "selection" => explode ( ',', str_replace ( '.', '', $params ['extensions'] ) ) );
  379 + }
  380 +
  381 + $document_types = $kt->get_documenttypes ( $params );
  382 + $items [] = array ("name" => "__document_type", "index" => 0, "value" => $document_type, "control_type" => "lookup", "selection" => $document_types );
  383 +
  384 + foreach ( $detail as $fieldset ) {
  385 + foreach ( $fieldset ['fields'] as $field ) {
  386 +
  387 + $prepArray = array ('fieldset' => $fieldset ['fieldset'], 'name' => $field ['name'],
  388 +
  389 + // Change for value. If blank value is set to 1, change value to ''
  390 + // Overcomes issue of n/a
  391 + 'value' => ($document_id > 0 ? ($field ['blankvalue'] == '1' ? '' : $field ['value']) : ''),
  392 +
  393 + 'description' => $field ['description'], 'control_type' => $field ['control_type'], 'selection' => $field ['selection'], 'required' => $field ['required'], 'blankvalue' => $field ['blankvalue'], 'index' => $index );
  394 +
  395 + // Small Adjustment for multiselect to real type
  396 + if ($field ['control_type'] == 'multiselect') {
  397 + $prepArray ['control_type'] = $field ['options'] ['type'];
  398 + }
  399 +
  400 + if (isset ( $field ['options'] ['ishtml'] )) {
  401 + $prepArray ['ishtml'] = $field ['options'] ['ishtml'];
  402 + } else {
  403 + $prepArray ['ishtml'] = '0';
  404 + }
  405 +
  406 + if (isset ( $field ['options'] ['maxlength'] )) {
  407 + $prepArray ['maxlength'] = $field ['options'] ['maxlength'];
  408 + } else {
  409 + $prepArray ['maxlength'] = '-1';
  410 + }
  411 +
  412 + $items [] = $prepArray;
  413 + $index ++;
  414 + }
  415 + }
  416 +
  417 + $this->setResponse ( array ('id' => $title, 'items' => $items, 'count' => count ( $items ) ) );
  418 +
  419 + return true;
  420 + }
  421 +
  422 + public function get_documenttypes($params) {
  423 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  424 +
  425 + $kt = &$this->KT;
  426 +
  427 + $detail = $kt->get_documenttypes ();
  428 + $result = array ();
  429 + $items = array ();
  430 + for($i = 0; $i < count ( $detail ); $i ++) {
  431 + if (strtolower ( substr ( $detail [$i], - 5 ) ) != 'email') {
  432 + $items [] = array ('name' => $detail [$i] );
  433 + }
  434 + }
  435 + $this->setResponse ( array ('items' => $items, 'count' => count ( $items ) ) );
  436 + return true;
  437 + }
  438 +
  439 + function update_document_type($params) {
  440 + $kt = &$this->KT;
  441 + $document_id = ( int ) $params ['document_id'];
  442 + if ($document_id > 0) {
  443 + $document = $kt->get_document_by_id ( $document_id );
  444 + $document->change_document_type ( $params ['document_type'] );
  445 + $this->setResponse ( array ('status_code' => 0 ) );
  446 + return true;
  447 +
  448 + } else {
  449 + $this->addError ( "Invalid document Id : {$document_id}" );
  450 + $this->setResponse ( array ('status_code' => 1 ) );
  451 + return false;
  452 + }
  453 +
  454 + }
  455 +
  456 + /**
  457 + * Get a url for downloading the specified document
  458 + * Parameters:
  459 + * session_id
  460 + * app_type
  461 + * document_id
  462 + *
  463 + * @param unknown_type $params
  464 + */
  465 + function download_document($params, $returnResult = false){
  466 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  467 +
  468 + $kt = &$this->KT;
  469 + $params ['session_id'] = $params ['session_id'] ? $params ['session_id'] : $this->AuthInfo ['session'];
  470 + $params ['app_type'] = $params ['app_type'] ? $params ['app_type'] : $this->AuthInfo ['appType'];
  471 + $params ['app_type'] = 'air';
  472 + $multipart = isset ( $params ['multipart'] ) ? ( bool ) $params ['multipart'] : false;
  473 + $multipart = false;
  474 +
  475 + $this->Response->addDebug ( 'download_document Parameters', $params );
  476 +
  477 + $session_id = $params ['session_id'];
  478 +
  479 + $document = &$kt->get_document_by_id ( $params ['document_id'] );
  480 + // $docname='test.txt';
  481 + if (PEAR::isError ( $document )) {
  482 + $response ['message'] = $document->getMessage ();
  483 + $this->addDebug ( "download_document - cannot get $document_id - " . $document->getMessage (), $document );
  484 +
  485 + // $this->setResponse(new SOAP_Value('$this->response=',"{urn:$this->namespace}kt_response", $response));
  486 + $this->setResponse ( $response );
  487 + return;
  488 + }
  489 + $docname = $document->document->getFileName ();
  490 + $result = $document->download ();
  491 + if (PEAR::isError ( $result )) {
  492 + $response ['message'] = $result->getMessage ();
  493 + $this->setResponse ( array ('status_code' => 1, 'message' => $result->getMessage () ) );
  494 + return;
  495 + }
  496 +
  497 + $session = &$kt->get_session ();
  498 + $download_manager = new KTDownloadManager ( );
  499 + $download_manager->set_session ( $session->session );
  500 + $download_manager->cleanup ();
  501 + $url = $download_manager->allow_download ( $document, NULL, $multipart );
  502 + //http://ktair.dev?code=750f7a09d40a3d855f2897f417baf0bbb9a1f615&d=16&u=evm2pdkkhfagon47eh2b9slqj6
  503 + /*
  504 + $this->addDebug('url before split',$url);
  505 + $url=split('\?',$url);
  506 + $this->addDebug('url after split',$url);
  507 + $url=$url[0].'/ktwebservice/download.php?'.$url[1];
  508 + $this->addDebug('url after recombo',$url);
  509 + */
  510 +
  511 + $response ['status_code'] = 0;
  512 + $response ['message'] = $url . '&apptype=' . $params ['app_type'];
  513 + $response ['filename'] = $docname;
  514 +
  515 + $this->addDebug ( 'effective params', $params );
  516 +
  517 + if ($returnResult) {
  518 + return $response;
  519 + } else {
  520 + $this->setResponse ( $response );
  521 + }
  522 + }
  523 +
  524 + /**
  525 + * Get download URLS for multiple documents
  526 + * params contains:
  527 + * app_type
  528 + * documents = array of doc_id
  529 + *
  530 + * @param unknown_type $params
  531 + */
  532 + public function download_multiple_documents($params) {
  533 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  534 + $response = array ();
  535 + foreach ( $params ['documents'] as $docId ) {
  536 + $ret = $this->download_document ( array ('document_id' => $docId, 'app_type' => $params ['app_type'], 'multipart' => $params ['multipart'] ), true );
  537 + $this->Response->addDebug ( 'Trying to create Download Link for ' . $docId, $ret );
  538 + $rec = array ('filename' => $ret ['filename'], 'url' => $ret ['message'], 'succeeded' => $ret ['status_code'] == 0 ? true : false );
  539 + if (is_array ( $ret ))
  540 + $response [$docId] = $rec;
  541 + }
  542 + $this->setResponse ( $response );
  543 + }
  544 +
  545 + /**
  546 + * Checkout a Document
  547 + * params contains:
  548 + * document_id the id of the document
  549 + * reason the checkout reason
  550 + *
  551 + * @param array $params
  552 + *
  553 + */
  554 + function checkout_document($params) {
  555 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  556 + $responseType = 'kt_response';
  557 + $kt = &$this->KT;
  558 +
  559 + $document = &$kt->get_document_by_id ( $params ['document_id'] );
  560 + if (PEAR::isError ( $document )) {
  561 + $this->addError ( "checkout_document - cannot get documentid {$params['document_id']} - " . $document->getMessage () );
  562 + $this->setResponse ( array ('status_code' => 1, 'message' => $document->getMessage () ) );
  563 + return;
  564 + }
  565 +
  566 + $result = $document->checkout ( $params ['reason'] );
  567 + if (PEAR::isError ( $result )) {
  568 + $this->addError ( $result->getMessage () );
  569 + $this->setResponse ( array ('status_code' => 1, 'message' => $result->getMessage () ) );
  570 + return;
  571 + }
  572 +
  573 + $url = '';
  574 + if ($params ['download']) {
  575 + $download_manager = new KTDownloadManager ( );
  576 + $download_manager->set_session ( $params ['session_id'] );
  577 + $download_manager->cleanup ();
  578 + $url = $download_manager->allow_download ( $document );
  579 + }
  580 +
  581 + $this->setResponse ( array ('status_code' => 0, 'message' => $url ) );
  582 + }
  583 +
  584 + /**
  585 + * Checkin Document //TODO: Find out how upload works
  586 + * params contains:
  587 + * document_id
  588 + * filename
  589 + * reason
  590 + * tempfilename
  591 + *
  592 + * @param array $params
  593 + */
  594 + function checkin_document($params) {
  595 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  596 + $session_id = $this->AuthInfo ['session'];
  597 + $document_id = $params ['document_id'];
  598 + $filename = $params ['filename'];
  599 + $reason = $params ['reason'];
  600 + $tempfilename = $params ['tempfilename'];
  601 + $major_update = $this->bool($params['major_update']); //Force value into boolean container.
  602 + $application = $this->AuthInfo ['appType'];
  603 +
  604 + $kt = &$this->KT;
  605 +
  606 + // we need to add some security to ensure that people don't frig the checkin process to access restricted files.
  607 + // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome.
  608 + $upload_manager = new KTUploadManager ( );
  609 + if (! $upload_manager->is_valid_temporary_file ( $tempfilename )) {
  610 + $this->setResponse ( array ('status_code' => 12 ) );
  611 + return;
  612 + }
  613 +
  614 + $document = &$kt->get_document_by_id ( $document_id );
  615 + if (PEAR::isError ( $document )) {
  616 + $this->setResponse ( array ('status_code' => 13 ) );
  617 + }
  618 +
  619 + // checkin
  620 + $this->logInfo('kt.checkin_document','Parameter Inspector',$major_update);
  621 + $result = $document->checkin ( $filename, $reason, $tempfilename, $major_update );
  622 + if (PEAR::isError ( $result )) {
  623 + $this->setResponse ( array ('status_code' => 14 ) );
  624 + }
  625 +
  626 + // get status after checkin
  627 + //$this->response= $this->get_document_detail($session_id, $document_id);
  628 + $detail = $document->get_detail ();
  629 + $detail ['status_code'] = 0;
  630 + $detail ['message'] = '';
  631 +
  632 + $this->setResponse ( $detail );
  633 + }
  634 +
  635 + /**
  636 + * Upload a document
  637 + *
  638 + * @param unknown_type $arr
  639 + */
  640 + function add_document_with_metadata($arr) {
  641 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  642 + $session_id = $arr ['session_id'];
  643 + //error_reporting(E_ALL);
  644 + $metadata = array ();
  645 + $packed = $arr ['metadata'];
  646 +
  647 + //TODO: $meta is undefined - please revise
  648 + foreach ( $meta as $item ) {
  649 + $fieldSet = $item ['fieldset'];
  650 + unset ( $item ['fieldset'] );
  651 + $metadata [$fieldSet] ['fieldset'] = $fieldSet;
  652 + $metadata [$fieldSet] ['fields'] [] = $item;
  653 + }
  654 +
  655 + $kt = &$this->KT;
  656 +
  657 + $upload_manager = new KTUploadManager ( );
  658 + if (! $upload_manager->is_valid_temporary_file ( $arr ['tempfilename'] )) {
  659 + $this->addError ( 'Temporary File Not Valid' );
  660 + $this->setResponse ( array ('status_code' => 1, 'message' => 'Temporary File Not Valid' ) );
  661 + return false;
  662 + }
  663 + $this->addDebug ( '', 'Exited is_valid_temporary file' );
  664 +
  665 + $folder = &$kt->get_folder_by_id ( $arr ['folder_id'] );
  666 + if (PEAR::isError ( $folder )) {
  667 + $this->addError ( 'Could not find Folder ' . $arr ['folder_id'] );
  668 + $this->setResponse ( array ('status_code' => 1, 'message' => 'Could not find Folder ' . $arr ['folder_id'] ) );
  669 + return false;
  670 + }
  671 +
  672 + $document = &$folder->add_document ( $arr ['title'], $arr ['filename'], $arr ['documenttype'], $arr ['tempfilename'] );
  673 + if (PEAR::isError ( $document )) {
  674 + $this->addError ( "Could not add Document [title:{$arr['title']},filename:{$arr['filename']},documenttype:{$arr['documenttype']},tempfilename:{$arr['tempfilename']}]" );
  675 + $this->setResponse ( array ('status_code' => 1, 'message' => 'Could not add Document' ) );
  676 + return false;
  677 + }
  678 +
  679 + $document_id = $document->get_documentid ();
  680 +
  681 + $update_result = $this->update_document_metadata ( $arr ['session_id'], $document_id, $metadata, $arr ['application'], array () );
  682 +
  683 + $status_code = $update_result ['status_code'];
  684 + if ($status_code != 0) {
  685 + $this->delete_document ( array ('session_id' => $arr ['session_id'], 'document_id' => $document_id, 'reason' => 'Rollback because metadata could not be added', 'application' => $arr ['application'] ) );
  686 + $this->response = $update_result;
  687 + }
  688 +
  689 + $result = $document->mergeWithLastMetadataVersion ();
  690 + if (PEAR::isError ( $result )) {
  691 + // not much we can do, maybe just log!
  692 + }
  693 +
  694 + $this->response = array ('status_code' => 0, 'document_id' => $document_id );
  695 + }
  696 +
  697 + function create_empty_upload_file($params) {
  698 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  699 + $config = KTConfig::getSingleton ();
  700 + $this->addDebug ( 'KTConfig Singleton', $config );
  701 + $uploadFolder = $config->get ( 'webservice/uploadDirectory' );
  702 +
  703 + $result = array ();
  704 +
  705 + if ($file = fopen ( $uploadFolder . "/" . $params ['filename'], 'w' )) {
  706 + fclose ( $file );
  707 + $result ['status_code'] = '0';
  708 + $result ['filename'] = $uploadFolder . "/" . $params ['filename'];
  709 + } else {
  710 + $result ['status_code'] = '1';
  711 + $result ['filename'] = $uploadFolder . "/" . $params ['filename'];
  712 + }
  713 + $this->setResponse ( $result );
  714 + return true;
  715 + }
  716 +
  717 + function get_all_client_policies() {
  718 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  719 + $config = KTConfig::getSingleton ();
  720 + $this->addDebug ( 'KTConfig Singleton', $config );
  721 +
  722 + $policies = array ('allowRememberPassword', 'captureReasonsCheckin', 'captureReasonsCheckout' );
  723 +
  724 + $returnPolicies = array ();
  725 +
  726 + foreach ( $policies as $policy_name ) {
  727 + $policyInfo = array ('name' => $policy_name, 'value' => serviceHelper::bool2str ( $config->get ( 'addInPolicies/' . $policy_name ) ), 'type' => 'boolean' );
  728 +
  729 + $returnPolicies [$policy_name] = $policyInfo;
  730 + }
  731 +
  732 + $languages = $this->get_languages ( true );
  733 +
  734 + $metadata = array ('totalProperty' => 'resultsCounter', 'root' => 'languages', 'fields' => array ('isoCode', 'language' ) );
  735 +
  736 + $finalArray = array ();
  737 + $finalArray ['metaData'] = $metadata;
  738 + $finalArray ['policies'] = $returnPolicies;
  739 + $finalArray ['languages'] = $languages ['languages'];
  740 + $finalArray ['defaultLanguage'] = $languages ['defaultLanguage'];
  741 + $finalArray ['resultsCounter'] = $languages ['count'];
  742 +
  743 + $this->setResponse ( $finalArray );
  744 + return true;
  745 + }
  746 +
  747 + function get_all_explorer_policies() {
  748 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  749 + $config = KTConfig::getSingleton ();
  750 + $this->addDebug ( 'KTConfig Singleton', $config );
  751 +
  752 + $policies = array ('allowRememberPassword', 'explorerMetadataCapture', 'officeMetadataCapture', 'captureReasonsCheckin', 'captureReasonsCheckout', 'captureReasonsDelete', 'captureReasonsCancelCheckout', 'captureReasonsCopyInKT', 'captureReasonsMoveInKT', 'forceSameNameCheckin' );
  753 +
  754 + $returnPolicies = array ();
  755 + $test = $config->get ( 'clientToolPolicies/allowRememberPassword' );
  756 + global $default;
  757 + $default->log->error ( 'I am here-' . $test );
  758 + foreach ( $policies as $policy_name ) {
  759 + $policyInfo = array ('name' => $policy_name, 'value' => serviceHelper::bool2str ( $config->get ( 'clientToolPolicies/' . $policy_name ) ), 'type' => 'boolean' );
  760 +
  761 + $returnPolicies [$policy_name] = $policyInfo;
  762 + }
  763 +
  764 + $languages = $this->get_languages ( true );
  765 +
  766 + $metadata = array ('totalProperty' => 'resultsCounter', 'root' => 'languages', 'fields' => array ('isoCode', 'language' ) );
  767 +
  768 + $finalArray = array ();
  769 + $finalArray ['metaData'] = $metadata;
  770 + $finalArray ['policies'] = $returnPolicies;
  771 + $finalArray ['languages'] = $languages ['languages'];
  772 + $finalArray ['defaultLanguage'] = $languages ['defaultLanguage'];
  773 + $finalArray ['resultsCounter'] = $languages ['count'];
  774 +
  775 + $this->setResponse ( $finalArray );
  776 + return true;
  777 + }
  778 +
  779 + public function switchlang($params) {
  780 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  781 + setcookie ( "kt_language", $params ['lang'], 2147483647, '/' );
  782 + }
  783 +
  784 + function add_document_params($params) {
  785 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  786 + $folder_id = $params ['folder_id'];
  787 + $title = $params ['title'];
  788 + $filename = $params ['filename'];
  789 + $documenttype = $params ['documenttype'];
  790 + $tempfilename = $params ['tempfilename'];
  791 + $application = $params ['application'];
  792 +
  793 + $this->addDebug ( '', 'Entered add_document' );
  794 + $kt = &$this->KT;
  795 +
  796 + $upload_manager = new KTUploadManager ( );
  797 + if (! $upload_manager->is_valid_temporary_file ( $tempfilename )) {
  798 + $this->addError ( 'Temporary File Not Valid' );
  799 + $this->setResponse ( array ('status_code' => 1 ) );
  800 + return false;
  801 + }
  802 + $this->addDebug ( '', 'Exited is_valid_temporary file' );
  803 +
  804 + $folder = &$kt->get_folder_by_id ( $folder_id );
  805 + if (PEAR::isError ( $folder )) {
  806 + $this->addError ( 'Could not find Folder ' . $folder_id );
  807 + $this->setResponse ( array ('status_code' => 1 ) );
  808 + return false;
  809 + }
  810 +
  811 + $this->addDebug ( '', 'Exited get_folder_by_id' );
  812 +
  813 + $document = &$folder->add_document ( $title, $filename, $documenttype, $tempfilename );
  814 + if (PEAR::isError ( $document )) {
  815 + $this->addError ( "Could add Document [title:{$title},filename:{$filename},documenttype:{$documenttype},tempfilename:{$tempfilename}]" );
  816 + $this->setResponse ( array ('status_code' => 1 ) );
  817 + return false;
  818 + }
  819 +
  820 + $this->addDebug ( '', 'Exited folder add_document' );
  821 +
  822 + $detail = $document->get_detail ();
  823 + $detail ['status_code'] = 0;
  824 + $detail ['message'] = '';
  825 +
  826 + $this->setResponse ( $detail );
  827 + }
  828 +
  829 + function delete_document($params) {
  830 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  831 + $session_id = $params ['session_id'];
  832 + $document_id = $params ['document_id'];
  833 + $reason = $params ['reason'];
  834 + $application = $params ['application'];
  835 +
  836 + $kt = &$this->KT;
  837 +
  838 + $document = &$kt->get_document_by_id ( $document_id );
  839 + if (PEAR::isError ( $document )) {
  840 + $this->addError ( "Invalid document {$document_id}" );
  841 + $this->setResponse ( array ('status_code' => 1 ) );
  842 + return false;
  843 + }
  844 +
  845 + $result = $document->delete ( $reason );
  846 + if (PEAR::isError ( $result )) {
  847 + $this->addError ( "Could not delete document {$document_id}" );
  848 + $this->setResponse ( array ('status_code' => 1 ) );
  849 + return false;
  850 + }
  851 + $this->setResponse ( array ('status_code' => 0 ) );
  852 + return true;
  853 + }
  854 +
  855 + private function update_document_metadata($session_id, $document_id, $metadata, $application, $sysdata = null) {
  856 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  857 + $this->addDebug ( 'update_document_metadata', 'entered update_document_metadata' );
  858 + $kt = &$this->KT;
  859 + $responseType = 'kt_document_detail';
  860 +
  861 + $document = &$kt->get_document_by_id ( $document_id );
  862 + if (PEAR::isError ( $document )) {
  863 + return array ('status_code' => 1, 'error' => 'Error getting document' );
  864 + }
  865 +
  866 + $result = $document->update_metadata ( $metadata );
  867 + if (PEAR::isError ( $result )) {
  868 + return array ('status_code' => 1, 'error' => 'Error updating metadata' );
  869 + }
  870 +
  871 + $result = $document->update_sysdata ( $sysdata );
  872 + if (PEAR::isError ( $result )) {
  873 + return array ('status_code' => 1, 'error' => 'Error update_sysdata' );
  874 + }
  875 +
  876 + return array ('status_code' => 0 );
  877 + }
  878 +
  879 + function get_client_policy($arr) {
  880 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  881 + $policy_name = $arr ['policy_name'];
  882 +
  883 + $config = KTConfig::getSingleton ();
  884 +
  885 + $policy = array ('name' => $policy_name, 'value' => serviceHelper::bool2str ( $config->get ( $policy_name ) ), 'type' => 'boolean' );
  886 +
  887 + $response ['policy'] = $policy;
  888 + $response ['message'] = 'Knowledgetree client policies retrieval succeeded.';
  889 + $response ['status_code'] = 0;
  890 +
  891 + $this->setResponse ( $response );
  892 + return true;
  893 + }
  894 +
  895 + function search($arr) {
  896 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  897 + $kt = &$this->KT;
  898 +
  899 + $listing = processSearchExpression ( "(GeneralText contains \"" . $arr ['query'] . "\")" );
  900 +
  901 + $result = $this->_processListing ( $listing, 'search', $arr );
  902 +
  903 + if (! count ( $result )) {
  904 + $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" ) );
  905 + } else {
  906 + $result = array_slice ( $result, 0, 200 );
  907 + }
  908 +
  909 + //$this->setResponse($result);
  910 + $this->setResponse ( array ('totalCount' => count ( $listing ), 'items' => $result ) );
  911 +
  912 + return true;
  913 + }
  914 +
  915 + public function update_metadata($arr) {
  916 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  917 + $metadata = array ();
  918 + $meta = $arr ['metadata'];
  919 +
  920 + $this->addDebug ( '', 'Entered add_document_with_metadata' );
  921 + $this->addDebug ( 'metadata received', $meta );
  922 +
  923 + $special = array ();
  924 + // foreach($apacked as $packed){
  925 + // foreach($packed as $key=>$val) {
  926 + // if(substr($val->name,0,2) != '__') {
  927 + // if(!is_array($metadata[$val->fieldset])) {
  928 + // $metadata[$val->fieldset]['fieldset']=$val->fieldset;
  929 + // $metadata[$val->fieldset]['fields']=array();
  930 + // }
  931 + // $metadata[$val->fieldset]['fields'][]=array(
  932 + // 'name'=>$val->name,
  933 + // 'value'=>$val->value
  934 + // );
  935 + // }else{
  936 + // $special[$val->name]=$val->value;
  937 + // }
  938 + // }
  939 + // }
  940 +
  941 +
  942 + /**
  943 +
  944 +Fatal error: Cannot unset string offsets in on line 981
  945 + */
  946 +
  947 + // foreach($meta as $item){
  948 + // $isSpecial=substr($item['name'],0,2)=='__';
  949 + // if($isSpecial){
  950 + // $special[$item['name']]=$item['value'];
  951 + // }else{
  952 + // $fieldSet=$item['fieldset'];
  953 + // unset($item['fieldset']);
  954 + // $metadata[$fieldSet]['fieldset']=$fieldSet;
  955 + // $metadata[$fieldSet]['fields'][]=$item;
  956 + // }
  957 + // }
  958 +
  959 +
  960 + $metadata = array ();
  961 + $special = array ();
  962 +
  963 + foreach ( $meta as $item ) {
  964 + if (substr ( $item ['name'], 0, 2 ) == '__') {
  965 + $special [$item ['name']] = $item ['value'];
  966 + } else {
  967 + $metadata [$item ['fieldset']] ['fieldset'] = $item ['fieldset'];
  968 + $metadata [$item ['fieldset']] ['fields'] [] = array ('name' => $item ['name'], 'value' => $item ['value'] );
  969 + }
  970 + }
  971 +
  972 + $this->addDebug ( 'after processing', array ('metadata' => $metadata, 'special' => $special ) );
  973 +
  974 + $document_id = $arr ['document_id'];
  975 +
  976 + $update_result = $this->update_document_metadata ( $arr ['session_id'], $document_id, $metadata, $arr ['application'], array () );
  977 + $this->addDebug ( '', '$this->response= from update_document_metadata' );
  978 +
  979 + $status_code = $update_result ['status_code'];
  980 + if ($status_code != 0) {
  981 + $this->setResponse ( $update_result );
  982 + }
  983 +
  984 + $kt = &$this->KT;
  985 +
  986 + if (! empty ( $special )) {
  987 + if ($document_id > 0) {
  988 + $document = $kt->get_document_by_id ( $document_id );
  989 +
  990 + if (isset ( $special ['__title'] )) {
  991 + $this->addDebug ( "Renaming to {$special['__title']}" );
  992 + $res = $document->rename ( $special ['__title'] );
  993 + }
  994 + }
  995 + }
  996 +
  997 + $this->setResponse ( array ('status_code' => 0, 'document_id' => $document_id ) );
  998 + }
  999 +
  1000 + function check_document_title($arr) {
  1001 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1002 + $kt = &$this->KT;
  1003 +
  1004 + $folder = $kt->get_folder_by_id ( $arr ['folder_id'] );
  1005 + if (PEAR::isError ( $folder )) {
  1006 + $this->setResponse ( array ('status_code' => 1, 'reason' => 'No such folder' ) );
  1007 + return false;
  1008 + }
  1009 +
  1010 + $doc = $folder->get_document_by_name ( $arr ['title'] );
  1011 + if (PEAR::isError ( $doc )) {
  1012 + $this->setResponse ( array ('status_code' => 1, 'reason' => 'No document with that title ' . $arr ['title'] ) );
  1013 + return false;
  1014 + }
  1015 +
  1016 + $this->setResponse ( array ('status_code' => 0 ) );
  1017 + return true;
  1018 + }
  1019 +
  1020 + function cancel_checkout($params) {
  1021 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1022 + $kt = &$this->KT;
  1023 +
  1024 + $document = &$kt->get_document_by_id ( $params ['document_id'] );
  1025 + if (PEAR::isError ( $document )) {
  1026 + $this->setResponse ( array ('status_code' => 1, 'message' => $document->getMessage () ) );
  1027 + return false;
  1028 + }
  1029 +
  1030 + $result = $document->undo_checkout ( $params ['reason'] );
  1031 + if (PEAR::isError ( $result )) {
  1032 + $this->setResponse ( array ('status_code' => 1, 'message' => $result->getMessage () ) );
  1033 + return false;
  1034 + }
  1035 + $response ['status_code'] = 0;
  1036 + $this->setResponse ( $response );
  1037 + }
  1038 +
  1039 + function get_transaction_history($params) {
  1040 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1041 + $kt = &$this->KT;
  1042 +
  1043 + $document = &$kt->get_document_by_id ( $params ['document_id'] );
  1044 + if (PEAR::isError ( $document )) {
  1045 + $this->setResponse ( array ('status_code' => 1, 'message' => $document->getMessage () ) );
  1046 + return false;
  1047 + }
  1048 +
  1049 + $versions = $document->get_version_history ();
  1050 + $transactions = $document->get_transaction_history ();
  1051 + $response ['status_code'] = 0;
  1052 + $response ['transactions'] = $transactions;
  1053 + $response ['versions'] = $versions;
  1054 + $this->setResponse ( $response );
  1055 + }
  1056 +
  1057 + public function get_users_groups($params) {
  1058 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1059 + $kt = &$this->KT;
  1060 + $query = $params ['query'];
  1061 + //$start=$params['start'];
  1062 + //$page=$params['page'];
  1063 +
  1064 +
  1065 + $results = KTAPI_User::getList ( 'name LIKE "%' . $query . '%" AND id>0' );
  1066 + $returnArray = array ();
  1067 + if (count ( $results ) > 0) {
  1068 + foreach ( $results as $user ) {
  1069 + $returnArray [] = array ('emailid' => 'u_' . $user->getId (), 'name' => $user->getName (), 'to' => preg_replace ( '/(' . $query . ')/i', '<b>${0}</b>', $user->getName () ) );
  1070 + }
  1071 + }
  1072 +
  1073 + $groups = KTAPI_Group::getList ( 'name LIKE "%' . $query . '%"' );
  1074 + if (count ( $groups ) > 0) {
  1075 + foreach ( $groups as $group ) {
  1076 + $returnArray [] = array ('emailid' => 'g_' . $group->getId (), 'name' => $group->getName (), 'to' => preg_replace ( '/(' . $query . ')/i', '<b>${0}</b>', $group->getName () ) );
  1077 + }
  1078 + }
  1079 +
  1080 + $sendArray = array ('emails' => $returnArray, 'metaData' => array ('count' => count ( $finalArray ), 'root' => 'emails', fields => array ('name', 'to', 'emailid' ) ) );
  1081 + $this->setResponse ( $sendArray );
  1082 + return true;
  1083 + }
  1084 +
  1085 + function send_email($params) {
  1086 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1087 + $kt = &$this->KT;
  1088 +
  1089 + $message = $params ['message'];
  1090 + $list = $params ['users'];
  1091 + $list = explode ( ',', $list );
  1092 +
  1093 + $recipientsList = array ();
  1094 +
  1095 + foreach ( $list as $recipient ) {
  1096 + if (trim ( $recipient ) != '') { // check that value is present
  1097 + // if @ sign is present, signifies email address
  1098 + if (strpos ( $recipient, '@' ) === false) {
  1099 + $recipient = trim ( $recipient );
  1100 + switch (substr ( $recipient, 0, 2 )) {
  1101 + case 'u_' :
  1102 + $id = substr ( $recipient, 2 );
  1103 + $user = KTAPI_User::getById ( $id );
  1104 + if ($user != null) {
  1105 + $recipientsList [] = $user;
  1106 + }
  1107 + break;
  1108 + case 'g_' :
  1109 + $id = substr ( $recipient, 2 );
  1110 + $group = KTAPI_Group::getById ( $id );
  1111 + if ($group != null) {
  1112 + $recipientsList [] = $group;
  1113 + }
  1114 + break;
  1115 + }
  1116 + } else { // Email - just add to list
  1117 + $recipientsList [] = trim ( $recipient );
  1118 + }
  1119 + }
  1120 + }
  1121 +
  1122 +
  1123 + if (count ( $recipientsList ) == 0) {
  1124 + $this->setResponse ( array ('status' => 'norecipients' ) );
  1125 + return false;
  1126 + } else {
  1127 +
  1128 + foreach ($params ['documents'] as $documentId)
  1129 + {
  1130 + $document = $kt->get_document_by_id ( $documentId );
  1131 +
  1132 +
  1133 + $result = $document->email ( $recipientsList, $message, TRUE ); // true to attach document
  1134 + if (PEAR::isError ( $result )) {
  1135 + $this->setResponse ( array ('status' => $result->getMessage () ) );
  1136 + return false;
  1137 + }
  1138 + }
  1139 +
  1140 + $this->setResponse ( array ('status' => 'documentemailed' ) );
  1141 + }
  1142 + return true;
  1143 + }
  1144 +
  1145 + function is_latest_version($params) {
  1146 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1147 + $kt = &$this->KT;
  1148 +
  1149 + $documentId = $params ['document_id'];
  1150 + $contentId = $params ['content_id'];
  1151 +
  1152 + $result = $kt->is_latest_version ( $documentId, $contentId );
  1153 +
  1154 + $this->setResponse ( $result );
  1155 + return true;
  1156 + }
  1157 +
  1158 + function check_permission($params) {
  1159 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1160 + $kt = &$this->KT;
  1161 +
  1162 + $user = $kt->get_user ();
  1163 + $document = $kt->get_document_by_id ( $params ['document_id'] );
  1164 + $folder = &$kt->get_folder_by_id ( $document->ktapi_folder->folderid );
  1165 + $folderDetail = $folder->get_detail ();
  1166 + $permissions = $folderDetail ['permissions'];
  1167 + if ($user->getId () == $document->document->getCheckedOutUserID ()) {
  1168 + $permissions .= 'E';
  1169 + }
  1170 +
  1171 + $this->setResponse ( array ('status_code' => 0, 'permissions' => $permissions ) );
  1172 + return true;
  1173 + }
  1174 +
  1175 + function copydocument($params) {
  1176 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1177 + $kt = &$this->KT;
  1178 +
  1179 + $response = $kt->copy_document ( $params ['documentid'], $params ['destfolderid'], $params ['reason'], $params ['title'], $params ['filename'] );
  1180 + if ($response ['status_code'] == 0) {
  1181 + $this->setResponse ( array ('status_code' => 0, 'status' => 'itemupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Document Copied' ), 'message' => $this->xlate ( 'Document has been successfully copied' ) ) );
  1182 + return true;
  1183 + } else {
  1184 + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to copy document' ), 'message' => $this->xlate ( 'Unable to copy document' ) ) );
  1185 + return false;
  1186 + }
  1187 + }
  1188 +
  1189 + function movedocument($params) {
  1190 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1191 + $kt = $this->KT;
  1192 +
  1193 + $response = $kt->move_document ( $params ['documentid'], $params ['destfolderid'], $params ['reason'], $params ['title'], $params ['filename'] );
  1194 + if ($response ['status_code'] == 0) {
  1195 + $this->setResponse ( array ('status_code' => 0, 'status' => 'itemupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Document Moved' ), 'message' => $this->xlate ( 'Document has been successfully moved' ) ) );
  1196 + return true;
  1197 + } else {
  1198 + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to move document' ), 'message' => $this->xlate ( 'Unable to move document' ) ) );
  1199 + return false;
  1200 + }
  1201 +
  1202 + }
  1203 +
  1204 + function copyfolder($params) {
  1205 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1206 + $kt = &$this->KT;
  1207 +
  1208 + $response = $kt->copy_folder ( $params ['sourcefolderid'], $params ['destfolderid'], $params ['reason'] );
  1209 + if ($response ['status_code'] == 0) {
  1210 + $this->setResponse ( array ('status_code' => 0, 'status' => 'itemupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Folder Copied' ), 'message' => $this->xlate ( 'Folder has been successfully copied' ) ) );
  1211 + return true;
  1212 + } else {
  1213 + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to copy folder' ), 'message' => $this->xlate ( 'Unable to copy folder' ) ) );
  1214 + return false;
  1215 + }
  1216 +
  1217 + }
  1218 +
  1219 + function movefolder($params) {
  1220 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1221 + $kt = &$this->KT;
  1222 +
  1223 + $response = $kt->move_folder ( $params ['sourcefolderid'], $params ['destfolderid'], $params ['reason'] );
  1224 + if ($response ['status_code'] == 0) {
  1225 + $this->setResponse ( array ('status_code' => 0, 'status' => 'itemupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Folder Moved' ), 'message' => $this->xlate ( 'Folder has been successfully moved' ) ) );
  1226 + return true;
  1227 + } else {
  1228 + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to move folder' ), 'message' => $this->xlate ( 'Unable to move folder' ) ) );
  1229 + return false;
  1230 + }
  1231 + }
  1232 +
  1233 + function renamefolder($params) {
  1234 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1235 + $kt = &$this->KT;
  1236 +
  1237 + $response = $kt->rename_folder ( $params ['currentfolderid'], $params ['newname'] );
  1238 + if ($response ['status_code'] == 0) {
  1239 + $this->setResponse ( array ('status_code' => 0, 'status' => 'folderupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Folder Renamed' ), 'message' => $this->xlate ( 'Folder has been successfully renamed' ) ) );
  1240 + return true;
  1241 + } else {
  1242 + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to rename folder' ), 'message' => $this->xlate ( 'Unable to rename folder' ) ) );
  1243 + return false;
  1244 + }
  1245 + }
  1246 +
  1247 + function addfolder($params) {
  1248 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1249 + $kt = &$this->KT;
  1250 + $this->addDebug ( 'parameters', $params );
  1251 + $response = $kt->create_folder ( $params ['currentfolderid'], $params ['newname'] );
  1252 + $this->setResponse ( $response );
  1253 + return true;
  1254 + }
  1255 +
  1256 + function deletefolder($params) {
  1257 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1258 + $kt = &$this->KT;
  1259 +
  1260 + $response = $kt->delete_folder ( $params ['folderid'], $params ['reason'] );
  1261 + if ($response ['status_code'] == 0) {
  1262 + $this->setResponse ( array ('status_code' => 0, 'status' => 'folderdeleted', 'icon' => 'success', 'title' => $this->xlate ( 'Folder Deleted' ), 'message' => $this->xlate ( 'Folder has been successfully deleted' ) ) );
  1263 + return true;
  1264 + } else {
  1265 + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to delete folder' ), 'message' => $this->xlate ( 'Unable to delete folder' ) ) );
  1266 + return false;
  1267 + }
  1268 + }
  1269 +
  1270 + function candeletefolder($arr) {
  1271 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  1272 + $kt = &$this->KT;
  1273 +
  1274 + $folder = &$kt->get_folder_by_id ( $arr ['folderid'] );
  1275 + if (PEAR::isError ( $folder )) {
  1276 + $this->setResponse ( 'error 1' );
  1277 + return false;
  1278 + }
  1279 +
  1280 + $listing = $folder->get_listing ( 1, 'DF' );
  1281 + if (count ( $listing ) == 0) {
  1282 + $this->setResponse ( array ('status_code' => 0, 'candelete' => TRUE ) );
  1283 + return true;
  1284 + } else {
  1285 + $this->setResponse ( array ('status_code' => 0, 'candelete' => FALSE ) );
  1286 + return true;
  1287 + }
  1288 + }
  1289 +
  1290 + function get_all_files($arr)
  1291 + {
  1292 + $kt=&$this->KT;
  1293 +
  1294 + $folders = array();
  1295 +
  1296 + if (is_array($arr['folderid'])) {
  1297 + foreach ($arr['folderid'] as $folder)
  1298 + {
  1299 + $folders[] = str_replace('F_', '', $folder);
  1300 + }
  1301 + } else {
  1302 + $folders[] = str_replace('F_', '', $arr['folderid']);
  1303 + }
  1304 +
  1305 +
  1306 + $this->listOfFiles = array();
  1307 + $this->listOfFoldersToBeCreated = array();
  1308 +
  1309 +
  1310 + foreach ($folders as $folderId)
  1311 + {
  1312 + $folder=&$kt->get_folder_by_id($folderId);
  1313 + if (PEAR::isError($folder)){
  1314 + $this->setResponse('error 1');
  1315 + return false;
  1316 + }
  1317 +
  1318 + // Note 50 is set here as the level depth, inaccurate
  1319 + $listing = $folder->get_listing(50, 'DFS'); //DFS
  1320 +
  1321 + if ($folderId == '1') {
  1322 + $path = 'KnowledgeTree';
  1323 + } else {
  1324 + $path = $folder->get_folder_name();
  1325 + }
  1326 +
  1327 + $this->addFolderToList($listing, $path);
  1328 +
  1329 + }
  1330 +
  1331 +
  1332 + // Sort Array by list of folders to be created in right order
  1333 + sort($this->listOfFoldersToBeCreated);
  1334 +
  1335 + $this->setResponse(array('items'=>$this->listOfFiles, 'folders'=>$this->listOfFoldersToBeCreated));
  1336 + return true;
  1337 + }
  1338 +
  1339 +
  1340 + private function addFolderToList(&$listing, $path)
  1341 + {
  1342 + if (!in_array($path, $this->listOfFoldersToBeCreated)) {
  1343 + $this->listOfFoldersToBeCreated[] = $path;
  1344 + }
  1345 +
  1346 + foreach ($listing as $item)
  1347 + {
  1348 + if ($item['item_type'] == 'D') {
  1349 + $this->listOfFiles[] = array(
  1350 + 'folderName' => $path,
  1351 + 'documentId' => $item['id'],
  1352 + 'filename' => $item['filename'],
  1353 + 'fullpath' => $path.'/'.$item['filename']
  1354 + );
  1355 +
  1356 + } else if ($item['item_type'] == 'F') {
  1357 +
  1358 +
  1359 +
  1360 + $this->addFolderToList($item['items'], $path.'/'.$item['filename']);
  1361 +
  1362 +
  1363 + } else if ($item['item_type'] == 'S') {
  1364 + if (isset($item['linked_document_id']) && $item['linked_document_id'] != '') {
  1365 +
  1366 +
  1367 + $this->listOfFiles[] = array(
  1368 + 'folderName' => $path,
  1369 + 'documentId' => $item['linked_document_id'],
  1370 + 'filename' => $item['filename'],
  1371 + 'fullpath' => $path.'/'.$item['filename']
  1372 + );
  1373 +
  1374 +
  1375 + // Need to delved again if it is a shortcut folder
  1376 + } else if (isset($item['linked_folder_id']) && $item['linked_folder_id']) {
  1377 +
  1378 +
  1379 +
  1380 + $folder = $this->KT->get_folder_by_id($item['linked_folder_id']);
  1381 +
  1382 + if (PEAR::isError($folder)){
  1383 +
  1384 + } else {
  1385 + // Note 50 is set here as the level depth, inaccurate
  1386 + $listing2 = $folder->get_listing(50, 'DFS'); //DF
  1387 +
  1388 + /*
  1389 + if ($folderId == '1') {
  1390 + $path = 'KnowledgeTree';
  1391 + } else {
  1392 + $path = $item['filename'];
  1393 + }*/
  1394 +
  1395 + $this->addFolderToList($listing2, $path.'/'.$item['filename']);
  1396 + }
  1397 +
  1398 +
  1399 +
  1400 +
  1401 + }
  1402 +
  1403 +
  1404 + }
  1405 +
  1406 + }
  1407 + }
  1408 +
  1409 + // ***********************************************
  1410 +
  1411 + private function convert_size_to_num($size)
  1412 + {
  1413 + //This function transforms the php.ini notation for numbers (like '2M') to an integer (2*1024*1024 in this case)
  1414 + $l = substr($size, -1);
  1415 + $ret = substr($size, 0, -1);
  1416 + switch(strtoupper($l)){
  1417 + case 'P':
  1418 + $ret *= 1024;
  1419 + case 'T':
  1420 + $ret *= 1024;
  1421 + case 'G':
  1422 + $ret *= 1024;
  1423 + case 'M':
  1424 + $ret *= 1024;
  1425 + case 'K':
  1426 + $ret *= 1024;
  1427 + break;
  1428 + }
  1429 + return $ret;
  1430 + }
  1431 +
  1432 + /*
  1433 + * Determing the maximum size a file can be to upload
  1434 + */
  1435 + function get_max_fileupload_size()
  1436 + {
  1437 + $post_max_size = $this->convert_size_to_num(ini_get('post_max_size'));
  1438 + $upload_max_filesize = $this->convert_size_to_num(ini_get('upload_max_filesize'));
  1439 +
  1440 + if ($upload_max_filesize < 0) {
  1441 + $max_upload_size = $post_max_size;
  1442 + } else {
  1443 + $max_upload_size = min($post_max_size, $upload_max_filesize);
  1444 + }
  1445 + $this->setResponse ( array ('status_code' => 0, 'maxsize' => $max_upload_size ) );
  1446 + return true;
  1447 + }
  1448 +
  1449 + /**
  1450 + * Method to get the recently viewed documents and folders.
  1451 + */
  1452 + function get_recently_viewed()
  1453 + {
  1454 + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' );
  1455 + $kt = &$this->KT;
  1456 +
  1457 +
  1458 + // Generate Folders List
  1459 + $returnFoldersArray = array();
  1460 +
  1461 + $folders = $kt->getRecentlyViewedFolders();
  1462 + foreach ($folders as $folder)
  1463 + {
  1464 + $folderObj = &$kt->get_folder_by_id ( $folder->getFolderId() );
  1465 +
  1466 + $folderArray = array();
  1467 + $folderArray['id'] = $folderObj->folderid;
  1468 + $folderArray['name'] = $folderObj->get_folder_name();
  1469 +
  1470 + $parentIds = explode(',', $folderObj->getParentFolderIds());
  1471 + $path = '/F_0';
  1472 +
  1473 + if (count($parentIds) > 0 && $folderObj->getParentFolderIds() != '') {
  1474 + foreach ($parentIds as $parentId)
  1475 + {
  1476 + $path .= '/F_'.$parentId;
  1477 + }
  1478 + }
  1479 +
  1480 + $path .= '/F_'.$folderObj->folderid;
  1481 +
  1482 + $folderArray['path'] = $path;
  1483 +
  1484 + $returnFoldersArray[] = $folderArray;
  1485 + }
  1486 +
  1487 +
  1488 + // Generate Documents List
  1489 + $returnDocumentArray = array();
  1490 +
  1491 + $items = $kt->getRecentlyViewedDocuments();
  1492 + foreach ($items as $item)
  1493 + {
  1494 + $document = $kt->get_document_by_id($item->getDocumentId());
  1495 + $documentDetail = $document->get_detail();
  1496 +
  1497 + $documentArray = array();
  1498 +
  1499 + $documentArray['id'] = $document->documentid;
  1500 + $documentArray['contentID'] = $document->documentid;
  1501 + $documentArray['title'] = $documentDetail['title'];
  1502 + $documentArray['folderId'] = $documentDetail['folder_id'];
  1503 +
  1504 + // Determine Icon Class
  1505 + $extpos = strrpos ( $documentDetail['filename'], '.' );
  1506 + if ($extpos === false) {
  1507 + $class = 'file-unknown';
  1508 + } else {
  1509 + $class = 'file-' . substr ( $documentDetail['filename'], $extpos + 1 ); // Get Extension without the dot
  1510 + }
  1511 + $documentArray['iconCls'] = $class;
  1512 +
  1513 + // Determine Icon Path
  1514 + $folderObj = $kt->get_folder_by_id ( $documentDetail['folder_id']);
  1515 + $parentIds = explode(',', $folderObj->getParentFolderIds());
  1516 + $path = '/F_0';
  1517 + if (count($parentIds) > 0 && $folderObj->getParentFolderIds() != '') {
  1518 + foreach ($parentIds as $parentId)
  1519 + {
  1520 + $path .= '/F_'.$parentId;
  1521 + }
  1522 + }
  1523 + $path .= '/F_'.$documentDetail['folder_id'];
  1524 +
  1525 + $documentArray['folderPath'] = $path;
  1526 +
  1527 + $returnDocumentArray[] = $documentArray;
  1528 + }
  1529 +
  1530 + $this->setResponse(array('documents'=>$returnDocumentArray, 'folders'=>$returnFoldersArray));
  1531 + }
  1532 +
  1533 +
  1534 + function get_folder_path($arr)
  1535 + {
  1536 + $kt=&$this->KT;
  1537 +
  1538 + $folderObj = &$kt->get_folder_by_id ( $arr ['folderId'] );
  1539 + if (PEAR::isError ( $folderObj )) {
  1540 + $this->setError ( "Could not get folder by Id: {$arr['folderId']}" );
  1541 + $this->setDebug ( 'FolderError', array ('kt' => $kt, 'folder' => $folderObj ) );
  1542 + return false;
  1543 + }
  1544 +
  1545 + $parentIds = explode(',', $folderObj->getParentFolderIds());
  1546 + $path = '/F_0';
  1547 +
  1548 + if (count($parentIds) > 0 && $folderObj->getParentFolderIds() != '') {
  1549 + foreach ($parentIds as $parentId)
  1550 + {
  1551 + $path .= '/F_'.$parentId;
  1552 + }
  1553 + }
  1554 +
  1555 + $path .= '/F_'.$folderObj->folderid;
  1556 +
  1557 +
  1558 + $this->setResponse ( array ('status_code' => 0, 'folderPath' => $path ) );
  1559 + }
  1560 +
  1561 +
  1562 +
  1563 +
  1564 +}
  1565 +
  1566 +
  1567 +?>
0 \ No newline at end of file 1568 \ No newline at end of file
webservice/clienttools/services/0.9.2/server.php 0 → 100644
  1 +<?php
  2 +class server extends client_service {
  3 + public function status(){
  4 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  5 + $this->setResponse(array('online'=>true));
  6 + }
  7 +
  8 + public function ping(){
  9 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  10 + $this->addResponse('pong',time());
  11 + }
  12 +
  13 + public function getToken(){
  14 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  15 +
  16 + }
  17 +
  18 + public function phpInfo(){
  19 + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function');
  20 + ob_start();
  21 + phpinfo();
  22 + $this->addResponse('phpinfo',ob_get_clean());
  23 + }
  24 +
  25 + }
  26 +?>
0 \ No newline at end of file 27 \ No newline at end of file