Commit f990d7446bb5343075cc60d4c37c5b168b50e7ad
Committed by
Megan Watson
1 parent
ded0f07a
Modified the Explorer CP versioning so that it now has a revision number built in
Committed by: Serge Meunier
Showing
5 changed files
with
1798 additions
and
1 deletions
webservice/clienttools/jsonWrapper.php
| ... | ... | @@ -118,7 +118,7 @@ class jsonWrapper{ |
| 118 | 118 | |
| 119 | 119 | public function getVersion(){ |
| 120 | 120 | $ver=$this->jsonArray['auth']['version']; |
| 121 | - $ver="{$ver['major']}.{$ver['minor']}"; | |
| 121 | + $ver="{$ver['major']}.{$ver['minor']}.{$ver['revision']}"; | |
| 122 | 122 | return $ver; |
| 123 | 123 | } |
| 124 | 124 | } | ... | ... |
webservice/clienttools/services/0.9.1/.htaccess
0 → 100644
| 1 | +# This file sets up the necessary PHP settings to run KnowledgeTree | |
| 2 | +# optimally. | |
| 3 | +# | |
| 4 | +# It is best that KnowledgeTree be allowed to manage its PHP and access | |
| 5 | +# permissions using these .htaccess files. This prevents direct access | |
| 6 | +# to libraries, scripts, and documents that should not be available via | |
| 7 | +# the web. | |
| 8 | +# | |
| 9 | +# By default, to facilitate quick testing of functionality, | |
| 10 | +# KnowledgeTree places the Documents directory within the KnowledgeTree | |
| 11 | +# web root. This, by default, would allow people to browse the | |
| 12 | +# documents in the DMS, bypassing the security permissions. The | |
| 13 | +# default .htaccess settings would prevent this. | |
| 14 | +# | |
| 15 | +# KnowledgeTree itself is able to deal with most PHP configurations, | |
| 16 | +# excepting "safe mode" currently, but is unable to handle certain | |
| 17 | +# inherent configuration options (for example, setting the upload size | |
| 18 | +# very low). Check the setup checklists (as described in the | |
| 19 | +# documentation) to see how your configuration is handled. | |
| 20 | +# | |
| 21 | +# The default .htaccess settings ensure that no workarounds occur in the | |
| 22 | +# PHP code, leading to better performance and robustness. | |
| 23 | +# | |
| 24 | +<IfModule mod_php5.c> | |
| 25 | +php_value default_mimetype text/html | |
| 26 | +php_value auto_prepend_file none | |
| 27 | +php_value auto_append_file none | |
| 28 | +php_flag display_startup_errors ON | |
| 29 | +php_flag display_errors ON | |
| 30 | +php_flag file_uploads ON | |
| 31 | +php_flag magic_quotes_gpc OFF | |
| 32 | +php_flag magic_quotes_runtime OFF | |
| 33 | +php_flag register_globals OFF | |
| 34 | +php_flag output_buffering OFF | |
| 35 | +php_flag session.auto_start OFF | |
| 36 | +</IfModule> | |
| 37 | + | |
| 38 | +<IfModule sapi_apache2.c> | |
| 39 | +php_value default_mimetype text/html | |
| 40 | +php_value auto_prepend_file none | |
| 41 | +php_value auto_append_file none | |
| 42 | +php_flag display_startup_errors ON | |
| 43 | +php_flag display_errors ON | |
| 44 | +php_flag file_uploads ON | |
| 45 | +php_flag magic_quotes_gpc OFF | |
| 46 | +php_flag magic_quotes_runtime OFF | |
| 47 | +php_flag register_globals OFF | |
| 48 | +php_flag output_buffering OFF | |
| 49 | +php_flag session.auto_start OFF | |
| 50 | +</IfModule> | |
| 51 | + | |
| 52 | +<IfModule mod_env.c> | |
| 53 | +SetEnv kt_htaccess_worked yes | |
| 54 | +SetEnvIf Authorization (.*) kt_auth=$1 | |
| 55 | +</IfModule> | |
| 56 | +LimitRequestBody 0 | |
| 57 | +DirectoryIndex index.html index.php | |
| 58 | +Options none | |
| 59 | +Options +ExecCGI | |
| 60 | +Options +SymLinksIfOwnerMatch | |
| 61 | +#AcceptPathInfo On | |
| 62 | + | |
| 63 | +AddOutputFilter DEFLATE text/html text/plain text/xml text/javascript application/x-javascript text/css | |
| 64 | +# The following seems to breaking things on ZendServer - kgf | |
| 65 | +#ExpiresActive ON | |
| 66 | +#ExpiresByType text/html "access plus 1 day" | |
| 67 | +#ExpiresByType text/css "access plus 1 day" | |
| 68 | +#ExpiresByType text/javascript "access plus 7 days" | |
| 69 | +#ExpiresByType application/x-javascript "access plus 7 days" | |
| 70 | +#ExpiresByType image/gif "access plus 1 month" | |
| 71 | +#ExpiresByType image/jpg "access plus 1 month" | |
| 72 | +#ExpiresByType image/png "access plus 1 month" | |
| 73 | +#ExpiresByType image/x-icon "access plus 1 month" | |
| 74 | + | |
| 75 | +# | |
| 76 | +# If you are having uploading larger documents, adjust the 16M examples | |
| 77 | +# below to increase the maximum file size. This is set to a reasonable | |
| 78 | +# size for testing and most usage patterns, as increased sizes may allow | |
| 79 | +# malicious users to use up resources. | |
| 80 | +# | |
| 81 | +<IfModule mod_php5.c> | |
| 82 | +php_value upload_max_filesize -1 | |
| 83 | +php_value post_max_size 2000M | |
| 84 | +php_value memory_limit -1 | |
| 85 | +php_value max_input_time -1 | |
| 86 | +php_value max_execution_time 0 | |
| 87 | +php_value error_reporting 5 | |
| 88 | +</IfModule> | |
| 89 | +<IfModule sapi_apache2.c> | |
| 90 | +php_value upload_max_filesize -1 | |
| 91 | +php_value post_max_size 2000M | |
| 92 | +php_value memory_limit -1 | |
| 93 | +php_value max_input_time -1 | |
| 94 | +php_value max_execution_time 0 | |
| 95 | +php_value error_reporting 5 | |
| 96 | +</IfModule> | |
| 97 | + | |
| 98 | +# Workaround for mod_auth when running php cgi | |
| 99 | +<IfModule mod_rewrite.c> | |
| 100 | +RewriteEngine on | |
| 101 | +RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] | |
| 102 | +</IfModule> | |
| 103 | + | |
| 104 | +#<IfModule mod_rewrite.c> | |
| 105 | +#RewriteEngine On | |
| 106 | +#RewriteBase / | |
| 107 | +## Set RewriteBase to the base directory that KnowledgeTree is viewable | |
| 108 | +## from via the web. So http://foo.org/ is /, and | |
| 109 | +## http://bar.com/knowledgeTree/ is /knowledgeTree | |
| 110 | +##RewriteBase /knowledgeTree | |
| 111 | +#RewriteCond %{REQUEST_FILENAME} !-f | |
| 112 | +#RewriteCond %{REQUEST_FILENAME}.php -f | |
| 113 | +#RewriteRule !^[^/]*.php - [C] | |
| 114 | +#RewriteRule ^([^/]*)([/].+)? $1.php [E=kt_path_info:$2,E=kt_orig_file:$1.php] | |
| 115 | +#<IfModule mod_env.c> | |
| 116 | +#SetEnv kt_no_extensions yes | |
| 117 | +#</IfModule> | |
| 118 | +#</IfModule> | ... | ... |
webservice/clienttools/services/0.9.1/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 | 162 | \ No newline at end of file | ... | ... |
webservice/clienttools/services/0.9.1/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'] : 'DF'); | |
| 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 | + if ($itemType == 'F') { | |
| 224 | + $qtip .= $this->xlate ( 'Folder name' ) . ": {$filename}<br>"; | |
| 225 | + $class = 'folder'; | |
| 226 | + $qtip .= $this->xlate ( 'Permissions:' ) . " {$perms}<br>"; | |
| 227 | + $qtip .= $canWrite ? $this->xlate ( 'You may add content to this folder' ) : $this->xlate ( 'You may not add content to this folder' ); | |
| 228 | + } | |
| 229 | + | |
| 230 | + //documents | |
| 231 | + else { | |
| 232 | + $qtip = ''; | |
| 233 | + $extpos = strrpos ( $filename, '.' ); | |
| 234 | + | |
| 235 | + if ($extpos === false) { | |
| 236 | + $class = 'file-unknown'; | |
| 237 | + } else { | |
| 238 | + $ext = substr ( $filename, $extpos ); // Get Extension including the dot | |
| 239 | + $class = 'file-' . substr ( $filename, $extpos + 1 ); // Get Extension without the dot | |
| 240 | + } | |
| 241 | + | |
| 242 | + $extensions = explode ( ',', $arr ['extensions'] ); | |
| 243 | + if (! in_array ( strtolower ( $ext ), $extensions ) && ! in_array ( '*', $extensions )) { | |
| 244 | + $includeMe = false; | |
| 245 | + } else { | |
| 246 | + $qtip .= $this->xlate ( 'Filename' ) . ": {$filename}<br>"; | |
| 247 | + $qtip .= $this->xlate ( 'File Size' ) . ": " . serviceHelper::fsize_desc ( $item ['filesize'] ) . "<br>"; | |
| 248 | + $qtip .= $this->xlate ( 'Modified' ) . ": {$item['modified_date']}<br>"; | |
| 249 | + $qtip .= $this->xlate ( 'Owner' ) . ": {$item['created_by']}<br>"; | |
| 250 | + $qtip .= $this->xlate ( 'Version' ) . ": {$item['version']}<br>"; | |
| 251 | + if (serviceHelper::bool2str ( strtolower ( $item ['is_immutable'] ) ) == 'true') { | |
| 252 | + $canWrite = false; | |
| 253 | + $immutable = true; | |
| 254 | + } | |
| 255 | + | |
| 256 | + if ($immutable) { | |
| 257 | + $qtip .= $this->xlate ( 'Status: Immutable' ) . '<br>'; | |
| 258 | + } else if (strtolower ( $item ['checked_out_by'] ) != 'n/a' && ($item ['checked_out_by'] != '')) { | |
| 259 | + $qtip .= $this->xlate ( 'Status: Checked out by' ) . " {$item['checked_out_by']}<br>"; | |
| 260 | + } else { | |
| 261 | + $qtip .= $this->xlate ( 'Status: Available' ) . '<br>'; | |
| 262 | + } | |
| 263 | + $qtip .= $this->xlate ( 'Permissions:' ) . " {$perms}<br>"; | |
| 264 | + | |
| 265 | + if ($immutable) { | |
| 266 | + $qtip .= $this->xlate ( 'This document is not editable' ); | |
| 267 | + } else if ($canWrite) { | |
| 268 | + $qtip .= $this->xlate ( 'You may edit this document' ); | |
| 269 | + } else { | |
| 270 | + $qtip .= $this->xlate ( 'This document is not editable' ); | |
| 271 | + } | |
| 272 | + } | |
| 273 | + } //end of if for files | |
| 274 | + if ($includeMe) { | |
| 275 | + $result [] = $this->$methodToIncludeItem ( $item, $class, $qtip ); | |
| 276 | + } | |
| 277 | + } | |
| 278 | + return $result; | |
| 279 | + } | |
| 280 | + | |
| 281 | + private function _processItemInclusion_folderContents($item, $class, $qtip) { | |
| 282 | + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' ); | |
| 283 | + 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'] ); | |
| 284 | + } | |
| 285 | + | |
| 286 | + private function _processItemInclusion_search($item, $class, $qtip) { | |
| 287 | + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' ); | |
| 288 | + if ($item ['filesize'] == 'n/a') { | |
| 289 | + $item ['filesize'] = - 1; | |
| 290 | + } | |
| 291 | + 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'] ); | |
| 292 | + } | |
| 293 | + | |
| 294 | + private function _processItemInclusion_grid($item, $class, $qtip) { | |
| 295 | + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' ); | |
| 296 | + //var_dump($item); | |
| 297 | + | |
| 298 | + | |
| 299 | + if ($item ['filesize'] == 'n/a') { | |
| 300 | + $item ['filesize'] = - 1; | |
| 301 | + } | |
| 302 | + | |
| 303 | + 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'] ); | |
| 304 | + } | |
| 305 | + | |
| 306 | + public function get_metadata($params) { | |
| 307 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 308 | + $kt = &$this->KT; | |
| 309 | + | |
| 310 | + if (substr ( $params ['document_id'], 0, 2 ) == 'D_') { | |
| 311 | + $params ['document_id'] = substr ( $params ['document_id'], 2 ); | |
| 312 | + } | |
| 313 | + | |
| 314 | + $document_id = ( int ) $params ['document_id']; | |
| 315 | + if ($document_id > 0) { | |
| 316 | + $document = $kt->get_document_by_id ( $params ['document_id'] ); | |
| 317 | + $detail = $document->get_metadata (); | |
| 318 | + $document_detail = $document->get_detail (); | |
| 319 | + $title = $document_detail ['title']; | |
| 320 | + $document_type = $document_detail ['document_type']; | |
| 321 | + | |
| 322 | + $document->addDocumentToUserHistory(); /* Added by Tohir */ | |
| 323 | + | |
| 324 | + } else { | |
| 325 | + if (isset ( $params ['document_type'] )) { | |
| 326 | + $document_type = $params ['document_type']; | |
| 327 | + } else { | |
| 328 | + $document_type = 'Default'; | |
| 329 | + } | |
| 330 | + $detail = $kt->get_document_type_metadata ( $document_type ); | |
| 331 | + $title = ""; | |
| 332 | + } | |
| 333 | + | |
| 334 | + $result = array (); | |
| 335 | + $items = array (); | |
| 336 | + $index = 0; | |
| 337 | + $items [] = array ("name" => "__title", "index" => 0, "value" => $title, "control_type" => "string" ); | |
| 338 | + | |
| 339 | + // Commented out for timebeing - will be used by 'Save in Format' | |
| 340 | + | |
| 341 | + | |
| 342 | + if (isset ( $params ['extensions'] )) { | |
| 343 | + | |
| 344 | + $fileParts = pathinfo ( $document_detail ['filename'] ); | |
| 345 | + | |
| 346 | + $items [] = array ("name" => "__document_extension", "index" => 0, "value" => strtolower ( $fileParts ['extension'] ), "control_type" => "lookup", "selection" => explode ( ',', str_replace ( '.', '', $params ['extensions'] ) ) ); | |
| 347 | + } | |
| 348 | + | |
| 349 | + $document_types = $kt->get_documenttypes ( $params ); | |
| 350 | + $items [] = array ("name" => "__document_type", "index" => 0, "value" => $document_type, "control_type" => "lookup", "selection" => $document_types ); | |
| 351 | + | |
| 352 | + foreach ( $detail as $fieldset ) { | |
| 353 | + foreach ( $fieldset ['fields'] as $field ) { | |
| 354 | + | |
| 355 | + $prepArray = array ('fieldset' => $fieldset ['fieldset'], 'name' => $field ['name'], | |
| 356 | + | |
| 357 | + // Change for value. If blank value is set to 1, change value to '' | |
| 358 | + // Overcomes issue of n/a | |
| 359 | + 'value' => ($document_id > 0 ? ($field ['blankvalue'] == '1' ? '' : $field ['value']) : ''), | |
| 360 | + | |
| 361 | + 'description' => $field ['description'], 'control_type' => $field ['control_type'], 'selection' => $field ['selection'], 'required' => $field ['required'], 'blankvalue' => $field ['blankvalue'], 'index' => $index ); | |
| 362 | + | |
| 363 | + // Small Adjustment for multiselect to real type | |
| 364 | + if ($field ['control_type'] == 'multiselect') { | |
| 365 | + $prepArray ['control_type'] = $field ['options'] ['type']; | |
| 366 | + } | |
| 367 | + | |
| 368 | + if (isset ( $field ['options'] ['ishtml'] )) { | |
| 369 | + $prepArray ['ishtml'] = $field ['options'] ['ishtml']; | |
| 370 | + } else { | |
| 371 | + $prepArray ['ishtml'] = '0'; | |
| 372 | + } | |
| 373 | + | |
| 374 | + if (isset ( $field ['options'] ['maxlength'] )) { | |
| 375 | + $prepArray ['maxlength'] = $field ['options'] ['maxlength']; | |
| 376 | + } else { | |
| 377 | + $prepArray ['maxlength'] = '-1'; | |
| 378 | + } | |
| 379 | + | |
| 380 | + $items [] = $prepArray; | |
| 381 | + $index ++; | |
| 382 | + } | |
| 383 | + } | |
| 384 | + | |
| 385 | + $this->setResponse ( array ('id' => $title, 'items' => $items, 'count' => count ( $items ) ) ); | |
| 386 | + | |
| 387 | + return true; | |
| 388 | + } | |
| 389 | + | |
| 390 | + public function get_documenttypes($params) { | |
| 391 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 392 | + | |
| 393 | + $kt = &$this->KT; | |
| 394 | + | |
| 395 | + $detail = $kt->get_documenttypes (); | |
| 396 | + $result = array (); | |
| 397 | + $items = array (); | |
| 398 | + for($i = 0; $i < count ( $detail ); $i ++) { | |
| 399 | + if (strtolower ( substr ( $detail [$i], - 5 ) ) != 'email') { | |
| 400 | + $items [] = array ('name' => $detail [$i] ); | |
| 401 | + } | |
| 402 | + } | |
| 403 | + $this->setResponse ( array ('items' => $items, 'count' => count ( $items ) ) ); | |
| 404 | + return true; | |
| 405 | + } | |
| 406 | + | |
| 407 | + function update_document_type($params) { | |
| 408 | + $kt = &$this->KT; | |
| 409 | + $document_id = ( int ) $params ['document_id']; | |
| 410 | + if ($document_id > 0) { | |
| 411 | + $document = $kt->get_document_by_id ( $document_id ); | |
| 412 | + $document->change_document_type ( $params ['document_type'] ); | |
| 413 | + $this->setResponse ( array ('status_code' => 0 ) ); | |
| 414 | + return true; | |
| 415 | + | |
| 416 | + } else { | |
| 417 | + $this->addError ( "Invalid document Id : {$document_id}" ); | |
| 418 | + $this->setResponse ( array ('status_code' => 1 ) ); | |
| 419 | + return false; | |
| 420 | + } | |
| 421 | + | |
| 422 | + } | |
| 423 | + | |
| 424 | + /** | |
| 425 | + * Get a url for downloading the specified document | |
| 426 | + * Parameters: | |
| 427 | + * session_id | |
| 428 | + * app_type | |
| 429 | + * document_id | |
| 430 | + * | |
| 431 | + * @param unknown_type $params | |
| 432 | + */ | |
| 433 | + function download_document($params, $returnResult = false){ | |
| 434 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 435 | + | |
| 436 | + $kt = &$this->KT; | |
| 437 | + $params ['session_id'] = $params ['session_id'] ? $params ['session_id'] : $this->AuthInfo ['session']; | |
| 438 | + $params ['app_type'] = $params ['app_type'] ? $params ['app_type'] : $this->AuthInfo ['appType']; | |
| 439 | + $params ['app_type'] = 'air'; | |
| 440 | + $multipart = isset ( $params ['multipart'] ) ? ( bool ) $params ['multipart'] : false; | |
| 441 | + $multipart = false; | |
| 442 | + | |
| 443 | + $this->Response->addDebug ( 'download_document Parameters', $params ); | |
| 444 | + | |
| 445 | + $session_id = $params ['session_id']; | |
| 446 | + | |
| 447 | + $document = &$kt->get_document_by_id ( $params ['document_id'] ); | |
| 448 | + // $docname='test.txt'; | |
| 449 | + if (PEAR::isError ( $document )) { | |
| 450 | + $response ['message'] = $document->getMessage (); | |
| 451 | + $this->addDebug ( "download_document - cannot get $document_id - " . $document->getMessage (), $document ); | |
| 452 | + | |
| 453 | + // $this->setResponse(new SOAP_Value('$this->response=',"{urn:$this->namespace}kt_response", $response)); | |
| 454 | + $this->setResponse ( $response ); | |
| 455 | + return; | |
| 456 | + } | |
| 457 | + $docname = $document->document->getFileName (); | |
| 458 | + $result = $document->download (); | |
| 459 | + if (PEAR::isError ( $result )) { | |
| 460 | + $response ['message'] = $result->getMessage (); | |
| 461 | + $this->setResponse ( array ('status_code' => 1, 'message' => $result->getMessage () ) ); | |
| 462 | + return; | |
| 463 | + } | |
| 464 | + | |
| 465 | + $session = &$kt->get_session (); | |
| 466 | + $download_manager = new KTDownloadManager ( ); | |
| 467 | + $download_manager->set_session ( $session->session ); | |
| 468 | + $download_manager->cleanup (); | |
| 469 | + $url = $download_manager->allow_download ( $document, NULL, $multipart ); | |
| 470 | + //http://ktair.dev?code=750f7a09d40a3d855f2897f417baf0bbb9a1f615&d=16&u=evm2pdkkhfagon47eh2b9slqj6 | |
| 471 | + /* | |
| 472 | + $this->addDebug('url before split',$url); | |
| 473 | + $url=split('\?',$url); | |
| 474 | + $this->addDebug('url after split',$url); | |
| 475 | + $url=$url[0].'/ktwebservice/download.php?'.$url[1]; | |
| 476 | + $this->addDebug('url after recombo',$url); | |
| 477 | + */ | |
| 478 | + | |
| 479 | + $response ['status_code'] = 0; | |
| 480 | + $response ['message'] = $url . '&apptype=' . $params ['app_type']; | |
| 481 | + $response ['filename'] = $docname; | |
| 482 | + | |
| 483 | + $this->addDebug ( 'effective params', $params ); | |
| 484 | + | |
| 485 | + if ($returnResult) { | |
| 486 | + return $response; | |
| 487 | + } else { | |
| 488 | + $this->setResponse ( $response ); | |
| 489 | + } | |
| 490 | + } | |
| 491 | + | |
| 492 | + /** | |
| 493 | + * Get download URLS for multiple documents | |
| 494 | + * params contains: | |
| 495 | + * app_type | |
| 496 | + * documents = array of doc_id | |
| 497 | + * | |
| 498 | + * @param unknown_type $params | |
| 499 | + */ | |
| 500 | + public function download_multiple_documents($params) { | |
| 501 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 502 | + $response = array (); | |
| 503 | + foreach ( $params ['documents'] as $docId ) { | |
| 504 | + $ret = $this->download_document ( array ('document_id' => $docId, 'app_type' => $params ['app_type'], 'multipart' => $params ['multipart'] ), true ); | |
| 505 | + $this->Response->addDebug ( 'Trying to create Download Link for ' . $docId, $ret ); | |
| 506 | + $rec = array ('filename' => $ret ['filename'], 'url' => $ret ['message'], 'succeeded' => $ret ['status_code'] == 0 ? true : false ); | |
| 507 | + if (is_array ( $ret )) | |
| 508 | + $response [$docId] = $rec; | |
| 509 | + } | |
| 510 | + $this->setResponse ( $response ); | |
| 511 | + } | |
| 512 | + | |
| 513 | + /** | |
| 514 | + * Checkout a Document | |
| 515 | + * params contains: | |
| 516 | + * document_id the id of the document | |
| 517 | + * reason the checkout reason | |
| 518 | + * | |
| 519 | + * @param array $params | |
| 520 | + * | |
| 521 | + */ | |
| 522 | + function checkout_document($params) { | |
| 523 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 524 | + $responseType = 'kt_response'; | |
| 525 | + $kt = &$this->KT; | |
| 526 | + | |
| 527 | + $document = &$kt->get_document_by_id ( $params ['document_id'] ); | |
| 528 | + if (PEAR::isError ( $document )) { | |
| 529 | + $this->addError ( "checkout_document - cannot get documentid {$params['document_id']} - " . $document->getMessage () ); | |
| 530 | + $this->setResponse ( array ('status_code' => 1, 'message' => $document->getMessage () ) ); | |
| 531 | + return; | |
| 532 | + } | |
| 533 | + | |
| 534 | + $result = $document->checkout ( $params ['reason'] ); | |
| 535 | + if (PEAR::isError ( $result )) { | |
| 536 | + $this->addError ( $result->getMessage () ); | |
| 537 | + $this->setResponse ( array ('status_code' => 1, 'message' => $result->getMessage () ) ); | |
| 538 | + return; | |
| 539 | + } | |
| 540 | + | |
| 541 | + $url = ''; | |
| 542 | + if ($params ['download']) { | |
| 543 | + $download_manager = new KTDownloadManager ( ); | |
| 544 | + $download_manager->set_session ( $params ['session_id'] ); | |
| 545 | + $download_manager->cleanup (); | |
| 546 | + $url = $download_manager->allow_download ( $document ); | |
| 547 | + } | |
| 548 | + | |
| 549 | + $this->setResponse ( array ('status_code' => 0, 'message' => $url ) ); | |
| 550 | + } | |
| 551 | + | |
| 552 | + /** | |
| 553 | + * Checkin Document //TODO: Find out how upload works | |
| 554 | + * params contains: | |
| 555 | + * document_id | |
| 556 | + * filename | |
| 557 | + * reason | |
| 558 | + * tempfilename | |
| 559 | + * | |
| 560 | + * @param array $params | |
| 561 | + */ | |
| 562 | + function checkin_document($params) { | |
| 563 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 564 | + $session_id = $this->AuthInfo ['session']; | |
| 565 | + $document_id = $params ['document_id']; | |
| 566 | + $filename = $params ['filename']; | |
| 567 | + $reason = $params ['reason']; | |
| 568 | + $tempfilename = $params ['tempfilename']; | |
| 569 | + $major_update = $this->bool($params['major_update']); //Force value into boolean container. | |
| 570 | + $application = $this->AuthInfo ['appType']; | |
| 571 | + | |
| 572 | + $kt = &$this->KT; | |
| 573 | + | |
| 574 | + // we need to add some security to ensure that people don't frig the checkin process to access restricted files. | |
| 575 | + // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome. | |
| 576 | + $upload_manager = new KTUploadManager ( ); | |
| 577 | + if (! $upload_manager->is_valid_temporary_file ( $tempfilename )) { | |
| 578 | + $this->setResponse ( array ('status_code' => 12 ) ); | |
| 579 | + return; | |
| 580 | + } | |
| 581 | + | |
| 582 | + $document = &$kt->get_document_by_id ( $document_id ); | |
| 583 | + if (PEAR::isError ( $document )) { | |
| 584 | + $this->setResponse ( array ('status_code' => 13 ) ); | |
| 585 | + } | |
| 586 | + | |
| 587 | + // checkin | |
| 588 | + $this->logInfo('kt.checkin_document','Parameter Inspector',$major_update); | |
| 589 | + $result = $document->checkin ( $filename, $reason, $tempfilename, $major_update ); | |
| 590 | + if (PEAR::isError ( $result )) { | |
| 591 | + $this->setResponse ( array ('status_code' => 14 ) ); | |
| 592 | + } | |
| 593 | + | |
| 594 | + // get status after checkin | |
| 595 | + //$this->response= $this->get_document_detail($session_id, $document_id); | |
| 596 | + $detail = $document->get_detail (); | |
| 597 | + $detail ['status_code'] = 0; | |
| 598 | + $detail ['message'] = ''; | |
| 599 | + | |
| 600 | + $this->setResponse ( $detail ); | |
| 601 | + } | |
| 602 | + | |
| 603 | + /** | |
| 604 | + * Upload a document | |
| 605 | + * | |
| 606 | + * @param unknown_type $arr | |
| 607 | + */ | |
| 608 | + function add_document_with_metadata($arr) { | |
| 609 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 610 | + $session_id = $arr ['session_id']; | |
| 611 | + //error_reporting(E_ALL); | |
| 612 | + $metadata = array (); | |
| 613 | + $packed = $arr ['metadata']; | |
| 614 | + | |
| 615 | + //TODO: $meta is undefined - please revise | |
| 616 | + foreach ( $meta as $item ) { | |
| 617 | + $fieldSet = $item ['fieldset']; | |
| 618 | + unset ( $item ['fieldset'] ); | |
| 619 | + $metadata [$fieldSet] ['fieldset'] = $fieldSet; | |
| 620 | + $metadata [$fieldSet] ['fields'] [] = $item; | |
| 621 | + } | |
| 622 | + | |
| 623 | + $kt = &$this->KT; | |
| 624 | + | |
| 625 | + $upload_manager = new KTUploadManager ( ); | |
| 626 | + if (! $upload_manager->is_valid_temporary_file ( $arr ['tempfilename'] )) { | |
| 627 | + $this->addError ( 'Temporary File Not Valid' ); | |
| 628 | + $this->setResponse ( array ('status_code' => 1, 'message' => 'Temporary File Not Valid' ) ); | |
| 629 | + return false; | |
| 630 | + } | |
| 631 | + $this->addDebug ( '', 'Exited is_valid_temporary file' ); | |
| 632 | + | |
| 633 | + $folder = &$kt->get_folder_by_id ( $arr ['folder_id'] ); | |
| 634 | + if (PEAR::isError ( $folder )) { | |
| 635 | + $this->addError ( 'Could not find Folder ' . $arr ['folder_id'] ); | |
| 636 | + $this->setResponse ( array ('status_code' => 1, 'message' => 'Could not find Folder ' . $arr ['folder_id'] ) ); | |
| 637 | + return false; | |
| 638 | + } | |
| 639 | + | |
| 640 | + $document = &$folder->add_document ( $arr ['title'], $arr ['filename'], $arr ['documenttype'], $arr ['tempfilename'] ); | |
| 641 | + if (PEAR::isError ( $document )) { | |
| 642 | + $this->addError ( "Could not add Document [title:{$arr['title']},filename:{$arr['filename']},documenttype:{$arr['documenttype']},tempfilename:{$arr['tempfilename']}]" ); | |
| 643 | + $this->setResponse ( array ('status_code' => 1, 'message' => 'Could not add Document' ) ); | |
| 644 | + return false; | |
| 645 | + } | |
| 646 | + | |
| 647 | + $document_id = $document->get_documentid (); | |
| 648 | + | |
| 649 | + $update_result = $this->update_document_metadata ( $arr ['session_id'], $document_id, $metadata, $arr ['application'], array () ); | |
| 650 | + | |
| 651 | + $status_code = $update_result ['status_code']; | |
| 652 | + if ($status_code != 0) { | |
| 653 | + $this->delete_document ( array ('session_id' => $arr ['session_id'], 'document_id' => $document_id, 'reason' => 'Rollback because metadata could not be added', 'application' => $arr ['application'] ) ); | |
| 654 | + $this->response = $update_result; | |
| 655 | + } | |
| 656 | + | |
| 657 | + $result = $document->mergeWithLastMetadataVersion (); | |
| 658 | + if (PEAR::isError ( $result )) { | |
| 659 | + // not much we can do, maybe just log! | |
| 660 | + } | |
| 661 | + | |
| 662 | + $this->response = array ('status_code' => 0, 'document_id' => $document_id ); | |
| 663 | + } | |
| 664 | + | |
| 665 | + function create_empty_upload_file($params) { | |
| 666 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 667 | + $config = KTConfig::getSingleton (); | |
| 668 | + $this->addDebug ( 'KTConfig Singleton', $config ); | |
| 669 | + $uploadFolder = $config->get ( 'webservice/uploadDirectory' ); | |
| 670 | + | |
| 671 | + $result = array (); | |
| 672 | + | |
| 673 | + if ($file = fopen ( $uploadFolder . "/" . $params ['filename'], 'w' )) { | |
| 674 | + fclose ( $file ); | |
| 675 | + $result ['status_code'] = '0'; | |
| 676 | + $result ['filename'] = $uploadFolder . "/" . $params ['filename']; | |
| 677 | + } else { | |
| 678 | + $result ['status_code'] = '1'; | |
| 679 | + $result ['filename'] = $uploadFolder . "/" . $params ['filename']; | |
| 680 | + } | |
| 681 | + $this->setResponse ( $result ); | |
| 682 | + return true; | |
| 683 | + } | |
| 684 | + | |
| 685 | + function get_all_client_policies() { | |
| 686 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 687 | + $config = KTConfig::getSingleton (); | |
| 688 | + $this->addDebug ( 'KTConfig Singleton', $config ); | |
| 689 | + | |
| 690 | + $policies = array ('allowRememberPassword', 'captureReasonsCheckin', 'captureReasonsCheckout' ); | |
| 691 | + | |
| 692 | + $returnPolicies = array (); | |
| 693 | + | |
| 694 | + foreach ( $policies as $policy_name ) { | |
| 695 | + $policyInfo = array ('name' => $policy_name, 'value' => serviceHelper::bool2str ( $config->get ( 'addInPolicies/' . $policy_name ) ), 'type' => 'boolean' ); | |
| 696 | + | |
| 697 | + $returnPolicies [$policy_name] = $policyInfo; | |
| 698 | + } | |
| 699 | + | |
| 700 | + $languages = $this->get_languages ( true ); | |
| 701 | + | |
| 702 | + $metadata = array ('totalProperty' => 'resultsCounter', 'root' => 'languages', 'fields' => array ('isoCode', 'language' ) ); | |
| 703 | + | |
| 704 | + $finalArray = array (); | |
| 705 | + $finalArray ['metaData'] = $metadata; | |
| 706 | + $finalArray ['policies'] = $returnPolicies; | |
| 707 | + $finalArray ['languages'] = $languages ['languages']; | |
| 708 | + $finalArray ['defaultLanguage'] = $languages ['defaultLanguage']; | |
| 709 | + $finalArray ['resultsCounter'] = $languages ['count']; | |
| 710 | + | |
| 711 | + $this->setResponse ( $finalArray ); | |
| 712 | + return true; | |
| 713 | + } | |
| 714 | + | |
| 715 | + function get_all_explorer_policies() { | |
| 716 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 717 | + $config = KTConfig::getSingleton (); | |
| 718 | + $this->addDebug ( 'KTConfig Singleton', $config ); | |
| 719 | + | |
| 720 | + $policies = array ('allowRememberPassword', 'explorerMetadataCapture', 'officeMetadataCapture', 'captureReasonsCheckin', 'captureReasonsCheckout', 'captureReasonsDelete', 'captureReasonsCancelCheckout', 'captureReasonsCopyInKT', 'captureReasonsMoveInKT', 'forceSameNameCheckin' ); | |
| 721 | + | |
| 722 | + $returnPolicies = array (); | |
| 723 | + $test = $config->get ( 'clientToolPolicies/allowRememberPassword' ); | |
| 724 | + global $default; | |
| 725 | + $default->log->error ( 'I am here-' . $test ); | |
| 726 | + foreach ( $policies as $policy_name ) { | |
| 727 | + $policyInfo = array ('name' => $policy_name, 'value' => serviceHelper::bool2str ( $config->get ( 'clientToolPolicies/' . $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 | + public function switchlang($params) { | |
| 748 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 749 | + setcookie ( "kt_language", $params ['lang'], 2147483647, '/' ); | |
| 750 | + } | |
| 751 | + | |
| 752 | + function add_document_params($params) { | |
| 753 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 754 | + $folder_id = $params ['folder_id']; | |
| 755 | + $title = $params ['title']; | |
| 756 | + $filename = $params ['filename']; | |
| 757 | + $documenttype = $params ['documenttype']; | |
| 758 | + $tempfilename = $params ['tempfilename']; | |
| 759 | + $application = $params ['application']; | |
| 760 | + | |
| 761 | + $this->addDebug ( '', 'Entered add_document' ); | |
| 762 | + $kt = &$this->KT; | |
| 763 | + | |
| 764 | + $upload_manager = new KTUploadManager ( ); | |
| 765 | + if (! $upload_manager->is_valid_temporary_file ( $tempfilename )) { | |
| 766 | + $this->addError ( 'Temporary File Not Valid' ); | |
| 767 | + $this->setResponse ( array ('status_code' => 1 ) ); | |
| 768 | + return false; | |
| 769 | + } | |
| 770 | + $this->addDebug ( '', 'Exited is_valid_temporary file' ); | |
| 771 | + | |
| 772 | + $folder = &$kt->get_folder_by_id ( $folder_id ); | |
| 773 | + if (PEAR::isError ( $folder )) { | |
| 774 | + $this->addError ( 'Could not find Folder ' . $folder_id ); | |
| 775 | + $this->setResponse ( array ('status_code' => 1 ) ); | |
| 776 | + return false; | |
| 777 | + } | |
| 778 | + | |
| 779 | + $this->addDebug ( '', 'Exited get_folder_by_id' ); | |
| 780 | + | |
| 781 | + $document = &$folder->add_document ( $title, $filename, $documenttype, $tempfilename ); | |
| 782 | + if (PEAR::isError ( $document )) { | |
| 783 | + $this->addError ( "Could add Document [title:{$title},filename:{$filename},documenttype:{$documenttype},tempfilename:{$tempfilename}]" ); | |
| 784 | + $this->setResponse ( array ('status_code' => 1 ) ); | |
| 785 | + return false; | |
| 786 | + } | |
| 787 | + | |
| 788 | + $this->addDebug ( '', 'Exited folder add_document' ); | |
| 789 | + | |
| 790 | + $detail = $document->get_detail (); | |
| 791 | + $detail ['status_code'] = 0; | |
| 792 | + $detail ['message'] = ''; | |
| 793 | + | |
| 794 | + $this->setResponse ( $detail ); | |
| 795 | + } | |
| 796 | + | |
| 797 | + function delete_document($params) { | |
| 798 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 799 | + $session_id = $params ['session_id']; | |
| 800 | + $document_id = $params ['document_id']; | |
| 801 | + $reason = $params ['reason']; | |
| 802 | + $application = $params ['application']; | |
| 803 | + | |
| 804 | + $kt = &$this->KT; | |
| 805 | + | |
| 806 | + $document = &$kt->get_document_by_id ( $document_id ); | |
| 807 | + if (PEAR::isError ( $document )) { | |
| 808 | + $this->addError ( "Invalid document {$document_id}" ); | |
| 809 | + $this->setResponse ( array ('status_code' => 1 ) ); | |
| 810 | + return false; | |
| 811 | + } | |
| 812 | + | |
| 813 | + $result = $document->delete ( $reason ); | |
| 814 | + if (PEAR::isError ( $result )) { | |
| 815 | + $this->addError ( "Could not delete document {$document_id}" ); | |
| 816 | + $this->setResponse ( array ('status_code' => 1 ) ); | |
| 817 | + return false; | |
| 818 | + } | |
| 819 | + $this->setResponse ( array ('status_code' => 0 ) ); | |
| 820 | + return true; | |
| 821 | + } | |
| 822 | + | |
| 823 | + private function update_document_metadata($session_id, $document_id, $metadata, $application, $sysdata = null) { | |
| 824 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 825 | + $this->addDebug ( 'update_document_metadata', 'entered update_document_metadata' ); | |
| 826 | + $kt = &$this->KT; | |
| 827 | + $responseType = 'kt_document_detail'; | |
| 828 | + | |
| 829 | + $document = &$kt->get_document_by_id ( $document_id ); | |
| 830 | + if (PEAR::isError ( $document )) { | |
| 831 | + return array ('status_code' => 1, 'error' => 'Error getting document' ); | |
| 832 | + } | |
| 833 | + | |
| 834 | + $result = $document->update_metadata ( $metadata ); | |
| 835 | + if (PEAR::isError ( $result )) { | |
| 836 | + return array ('status_code' => 1, 'error' => 'Error updating metadata' ); | |
| 837 | + } | |
| 838 | + | |
| 839 | + $result = $document->update_sysdata ( $sysdata ); | |
| 840 | + if (PEAR::isError ( $result )) { | |
| 841 | + return array ('status_code' => 1, 'error' => 'Error update_sysdata' ); | |
| 842 | + } | |
| 843 | + | |
| 844 | + return array ('status_code' => 0 ); | |
| 845 | + } | |
| 846 | + | |
| 847 | + function get_client_policy($arr) { | |
| 848 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 849 | + $policy_name = $arr ['policy_name']; | |
| 850 | + | |
| 851 | + $config = KTConfig::getSingleton (); | |
| 852 | + | |
| 853 | + $policy = array ('name' => $policy_name, 'value' => serviceHelper::bool2str ( $config->get ( $policy_name ) ), 'type' => 'boolean' ); | |
| 854 | + | |
| 855 | + $response ['policy'] = $policy; | |
| 856 | + $response ['message'] = 'Knowledgetree client policies retrieval succeeded.'; | |
| 857 | + $response ['status_code'] = 0; | |
| 858 | + | |
| 859 | + $this->setResponse ( $response ); | |
| 860 | + return true; | |
| 861 | + } | |
| 862 | + | |
| 863 | + function search($arr) { | |
| 864 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 865 | + $kt = &$this->KT; | |
| 866 | + | |
| 867 | + $listing = processSearchExpression ( "(GeneralText contains \"" . $arr ['query'] . "\")" ); | |
| 868 | + | |
| 869 | + $result = $this->_processListing ( $listing, 'search', $arr ); | |
| 870 | + | |
| 871 | + if (! count ( $result )) { | |
| 872 | + $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" ) ); | |
| 873 | + } else { | |
| 874 | + $result = array_slice ( $result, 0, 200 ); | |
| 875 | + } | |
| 876 | + | |
| 877 | + //$this->setResponse($result); | |
| 878 | + $this->setResponse ( array ('totalCount' => count ( $listing ), 'items' => $result ) ); | |
| 879 | + | |
| 880 | + return true; | |
| 881 | + } | |
| 882 | + | |
| 883 | + public function update_metadata($arr) { | |
| 884 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 885 | + $metadata = array (); | |
| 886 | + $meta = $arr ['metadata']; | |
| 887 | + | |
| 888 | + $this->addDebug ( '', 'Entered add_document_with_metadata' ); | |
| 889 | + $this->addDebug ( 'metadata received', $meta ); | |
| 890 | + | |
| 891 | + $special = array (); | |
| 892 | + // foreach($apacked as $packed){ | |
| 893 | + // foreach($packed as $key=>$val) { | |
| 894 | + // if(substr($val->name,0,2) != '__') { | |
| 895 | + // if(!is_array($metadata[$val->fieldset])) { | |
| 896 | + // $metadata[$val->fieldset]['fieldset']=$val->fieldset; | |
| 897 | + // $metadata[$val->fieldset]['fields']=array(); | |
| 898 | + // } | |
| 899 | + // $metadata[$val->fieldset]['fields'][]=array( | |
| 900 | + // 'name'=>$val->name, | |
| 901 | + // 'value'=>$val->value | |
| 902 | + // ); | |
| 903 | + // }else{ | |
| 904 | + // $special[$val->name]=$val->value; | |
| 905 | + // } | |
| 906 | + // } | |
| 907 | + // } | |
| 908 | + | |
| 909 | + | |
| 910 | + /** | |
| 911 | + | |
| 912 | +Fatal error: Cannot unset string offsets in on line 981 | |
| 913 | + */ | |
| 914 | + | |
| 915 | + // foreach($meta as $item){ | |
| 916 | + // $isSpecial=substr($item['name'],0,2)=='__'; | |
| 917 | + // if($isSpecial){ | |
| 918 | + // $special[$item['name']]=$item['value']; | |
| 919 | + // }else{ | |
| 920 | + // $fieldSet=$item['fieldset']; | |
| 921 | + // unset($item['fieldset']); | |
| 922 | + // $metadata[$fieldSet]['fieldset']=$fieldSet; | |
| 923 | + // $metadata[$fieldSet]['fields'][]=$item; | |
| 924 | + // } | |
| 925 | + // } | |
| 926 | + | |
| 927 | + | |
| 928 | + $metadata = array (); | |
| 929 | + $special = array (); | |
| 930 | + | |
| 931 | + foreach ( $meta as $item ) { | |
| 932 | + if (substr ( $item ['name'], 0, 2 ) == '__') { | |
| 933 | + $special [$item ['name']] = $item ['value']; | |
| 934 | + } else { | |
| 935 | + $metadata [$item ['fieldset']] ['fieldset'] = $item ['fieldset']; | |
| 936 | + $metadata [$item ['fieldset']] ['fields'] [] = array ('name' => $item ['name'], 'value' => $item ['value'] ); | |
| 937 | + } | |
| 938 | + } | |
| 939 | + | |
| 940 | + $this->addDebug ( 'after processing', array ('metadata' => $metadata, 'special' => $special ) ); | |
| 941 | + | |
| 942 | + $document_id = $arr ['document_id']; | |
| 943 | + | |
| 944 | + $update_result = $this->update_document_metadata ( $arr ['session_id'], $document_id, $metadata, $arr ['application'], array () ); | |
| 945 | + $this->addDebug ( '', '$this->response= from update_document_metadata' ); | |
| 946 | + | |
| 947 | + $status_code = $update_result ['status_code']; | |
| 948 | + if ($status_code != 0) { | |
| 949 | + $this->setResponse ( $update_result ); | |
| 950 | + } | |
| 951 | + | |
| 952 | + $kt = &$this->KT; | |
| 953 | + | |
| 954 | + if (! empty ( $special )) { | |
| 955 | + if ($document_id > 0) { | |
| 956 | + $document = $kt->get_document_by_id ( $document_id ); | |
| 957 | + | |
| 958 | + if (isset ( $special ['__title'] )) { | |
| 959 | + $this->addDebug ( "Renaming to {$special['__title']}" ); | |
| 960 | + $res = $document->rename ( $special ['__title'] ); | |
| 961 | + } | |
| 962 | + } | |
| 963 | + } | |
| 964 | + | |
| 965 | + $this->setResponse ( array ('status_code' => 0, 'document_id' => $document_id ) ); | |
| 966 | + } | |
| 967 | + | |
| 968 | + function check_document_title($arr) { | |
| 969 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 970 | + $kt = &$this->KT; | |
| 971 | + | |
| 972 | + $folder = $kt->get_folder_by_id ( $arr ['folder_id'] ); | |
| 973 | + if (PEAR::isError ( $folder )) { | |
| 974 | + $this->setResponse ( array ('status_code' => 1, 'reason' => 'No such folder' ) ); | |
| 975 | + return false; | |
| 976 | + } | |
| 977 | + | |
| 978 | + $doc = $folder->get_document_by_name ( $arr ['title'] ); | |
| 979 | + if (PEAR::isError ( $doc )) { | |
| 980 | + $this->setResponse ( array ('status_code' => 1, 'reason' => 'No document with that title ' . $arr ['title'] ) ); | |
| 981 | + return false; | |
| 982 | + } | |
| 983 | + | |
| 984 | + $this->setResponse ( array ('status_code' => 0 ) ); | |
| 985 | + return true; | |
| 986 | + } | |
| 987 | + | |
| 988 | + function cancel_checkout($params) { | |
| 989 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 990 | + $kt = &$this->KT; | |
| 991 | + | |
| 992 | + $document = &$kt->get_document_by_id ( $params ['document_id'] ); | |
| 993 | + if (PEAR::isError ( $document )) { | |
| 994 | + $this->setResponse ( array ('status_code' => 1, 'message' => $document->getMessage () ) ); | |
| 995 | + return false; | |
| 996 | + } | |
| 997 | + | |
| 998 | + $result = $document->undo_checkout ( $params ['reason'] ); | |
| 999 | + if (PEAR::isError ( $result )) { | |
| 1000 | + $this->setResponse ( array ('status_code' => 1, 'message' => $result->getMessage () ) ); | |
| 1001 | + return false; | |
| 1002 | + } | |
| 1003 | + $response ['status_code'] = 0; | |
| 1004 | + $this->setResponse ( $response ); | |
| 1005 | + } | |
| 1006 | + | |
| 1007 | + function get_transaction_history($params) { | |
| 1008 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 1009 | + $kt = &$this->KT; | |
| 1010 | + | |
| 1011 | + $document = &$kt->get_document_by_id ( $params ['document_id'] ); | |
| 1012 | + if (PEAR::isError ( $document )) { | |
| 1013 | + $this->setResponse ( array ('status_code' => 1, 'message' => $document->getMessage () ) ); | |
| 1014 | + return false; | |
| 1015 | + } | |
| 1016 | + | |
| 1017 | + $versions = $document->get_version_history (); | |
| 1018 | + $transactions = $document->get_transaction_history (); | |
| 1019 | + $response ['status_code'] = 0; | |
| 1020 | + $response ['transactions'] = $transactions; | |
| 1021 | + $response ['versions'] = $versions; | |
| 1022 | + $this->setResponse ( $response ); | |
| 1023 | + } | |
| 1024 | + | |
| 1025 | + public function get_users_groups($params) { | |
| 1026 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 1027 | + $kt = &$this->KT; | |
| 1028 | + $query = $params ['query']; | |
| 1029 | + //$start=$params['start']; | |
| 1030 | + //$page=$params['page']; | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + $results = KTAPI_User::getList ( 'name LIKE "%' . $query . '%" AND id>0' ); | |
| 1034 | + $returnArray = array (); | |
| 1035 | + if (count ( $results ) > 0) { | |
| 1036 | + foreach ( $results as $user ) { | |
| 1037 | + $returnArray [] = array ('emailid' => 'u_' . $user->getId (), 'name' => $user->getName (), 'to' => preg_replace ( '/(' . $query . ')/i', '<b>${0}</b>', $user->getName () ) ); | |
| 1038 | + } | |
| 1039 | + } | |
| 1040 | + | |
| 1041 | + $groups = KTAPI_Group::getList ( 'name LIKE "%' . $query . '%"' ); | |
| 1042 | + if (count ( $groups ) > 0) { | |
| 1043 | + foreach ( $groups as $group ) { | |
| 1044 | + $returnArray [] = array ('emailid' => 'g_' . $group->getId (), 'name' => $group->getName (), 'to' => preg_replace ( '/(' . $query . ')/i', '<b>${0}</b>', $group->getName () ) ); | |
| 1045 | + } | |
| 1046 | + } | |
| 1047 | + | |
| 1048 | + $sendArray = array ('emails' => $returnArray, 'metaData' => array ('count' => count ( $finalArray ), 'root' => 'emails', fields => array ('name', 'to', 'emailid' ) ) ); | |
| 1049 | + $this->setResponse ( $sendArray ); | |
| 1050 | + return true; | |
| 1051 | + } | |
| 1052 | + | |
| 1053 | + function send_email($params) { | |
| 1054 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 1055 | + $kt = &$this->KT; | |
| 1056 | + | |
| 1057 | + $message = $params ['message']; | |
| 1058 | + $list = $params ['users']; | |
| 1059 | + $list = explode ( ',', $list ); | |
| 1060 | + | |
| 1061 | + $recipientsList = array (); | |
| 1062 | + | |
| 1063 | + foreach ( $list as $recipient ) { | |
| 1064 | + if (trim ( $recipient ) != '') { // check that value is present | |
| 1065 | + // if @ sign is present, signifies email address | |
| 1066 | + if (strpos ( $recipient, '@' ) === false) { | |
| 1067 | + $recipient = trim ( $recipient ); | |
| 1068 | + switch (substr ( $recipient, 0, 2 )) { | |
| 1069 | + case 'u_' : | |
| 1070 | + $id = substr ( $recipient, 2 ); | |
| 1071 | + $user = KTAPI_User::getById ( $id ); | |
| 1072 | + if ($user != null) { | |
| 1073 | + $recipientsList [] = $user; | |
| 1074 | + } | |
| 1075 | + break; | |
| 1076 | + case 'g_' : | |
| 1077 | + $id = substr ( $recipient, 2 ); | |
| 1078 | + $group = KTAPI_Group::getById ( $id ); | |
| 1079 | + if ($group != null) { | |
| 1080 | + $recipientsList [] = $group; | |
| 1081 | + } | |
| 1082 | + break; | |
| 1083 | + } | |
| 1084 | + } else { // Email - just add to list | |
| 1085 | + $recipientsList [] = trim ( $recipient ); | |
| 1086 | + } | |
| 1087 | + } | |
| 1088 | + } | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + if (count ( $recipientsList ) == 0) { | |
| 1092 | + $this->setResponse ( array ('status' => 'norecipients' ) ); | |
| 1093 | + return false; | |
| 1094 | + } else { | |
| 1095 | + | |
| 1096 | + foreach ($params ['documents'] as $documentId) | |
| 1097 | + { | |
| 1098 | + $document = $kt->get_document_by_id ( $documentId ); | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + $result = $document->email ( $recipientsList, $message, TRUE ); // true to attach document | |
| 1102 | + if (PEAR::isError ( $result )) { | |
| 1103 | + $this->setResponse ( array ('status' => $result->getMessage () ) ); | |
| 1104 | + return false; | |
| 1105 | + } | |
| 1106 | + } | |
| 1107 | + | |
| 1108 | + $this->setResponse ( array ('status' => 'documentemailed' ) ); | |
| 1109 | + } | |
| 1110 | + return true; | |
| 1111 | + } | |
| 1112 | + | |
| 1113 | + function is_latest_version($params) { | |
| 1114 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 1115 | + $kt = &$this->KT; | |
| 1116 | + | |
| 1117 | + $documentId = $params ['document_id']; | |
| 1118 | + $contentId = $params ['content_id']; | |
| 1119 | + | |
| 1120 | + $result = $kt->is_latest_version ( $documentId, $contentId ); | |
| 1121 | + | |
| 1122 | + $this->setResponse ( $result ); | |
| 1123 | + return true; | |
| 1124 | + } | |
| 1125 | + | |
| 1126 | + function check_permission($params) { | |
| 1127 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 1128 | + $kt = &$this->KT; | |
| 1129 | + | |
| 1130 | + $user = $kt->get_user (); | |
| 1131 | + $document = $kt->get_document_by_id ( $params ['document_id'] ); | |
| 1132 | + $folder = &$kt->get_folder_by_id ( $document->ktapi_folder->folderid ); | |
| 1133 | + $folderDetail = $folder->get_detail (); | |
| 1134 | + $permissions = $folderDetail ['permissions']; | |
| 1135 | + if ($user->getId () == $document->document->getCheckedOutUserID ()) { | |
| 1136 | + $permissions .= 'E'; | |
| 1137 | + } | |
| 1138 | + | |
| 1139 | + $this->setResponse ( array ('status_code' => 0, 'permissions' => $permissions ) ); | |
| 1140 | + return true; | |
| 1141 | + } | |
| 1142 | + | |
| 1143 | + function copydocument($params) { | |
| 1144 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 1145 | + $kt = &$this->KT; | |
| 1146 | + | |
| 1147 | + $response = $kt->copy_document ( $params ['documentid'], $params ['destfolderid'], $params ['reason'], $params ['title'], $params ['filename'] ); | |
| 1148 | + if ($response ['status_code'] == 0) { | |
| 1149 | + $this->setResponse ( array ('status_code' => 0, 'status' => 'itemupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Document Copied' ), 'message' => $this->xlate ( 'Document has been successfully copied' ) ) ); | |
| 1150 | + return true; | |
| 1151 | + } else { | |
| 1152 | + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to copy document' ), 'message' => $this->xlate ( 'Unable to copy document' ) ) ); | |
| 1153 | + return false; | |
| 1154 | + } | |
| 1155 | + } | |
| 1156 | + | |
| 1157 | + function movedocument($params) { | |
| 1158 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 1159 | + $kt = $this->KT; | |
| 1160 | + | |
| 1161 | + $response = $kt->move_document ( $params ['documentid'], $params ['destfolderid'], $params ['reason'], $params ['title'], $params ['filename'] ); | |
| 1162 | + if ($response ['status_code'] == 0) { | |
| 1163 | + $this->setResponse ( array ('status_code' => 0, 'status' => 'itemupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Document Moved' ), 'message' => $this->xlate ( 'Document has been successfully moved' ) ) ); | |
| 1164 | + return true; | |
| 1165 | + } else { | |
| 1166 | + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to move document' ), 'message' => $this->xlate ( 'Unable to move document' ) ) ); | |
| 1167 | + return false; | |
| 1168 | + } | |
| 1169 | + | |
| 1170 | + } | |
| 1171 | + | |
| 1172 | + function copyfolder($params) { | |
| 1173 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 1174 | + $kt = &$this->KT; | |
| 1175 | + | |
| 1176 | + $response = $kt->copy_folder ( $params ['sourcefolderid'], $params ['destfolderid'], $params ['reason'] ); | |
| 1177 | + if ($response ['status_code'] == 0) { | |
| 1178 | + $this->setResponse ( array ('status_code' => 0, 'status' => 'itemupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Folder Copied' ), 'message' => $this->xlate ( 'Folder has been successfully copied' ) ) ); | |
| 1179 | + return true; | |
| 1180 | + } else { | |
| 1181 | + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to copy folder' ), 'message' => $this->xlate ( 'Unable to copy folder' ) ) ); | |
| 1182 | + return false; | |
| 1183 | + } | |
| 1184 | + | |
| 1185 | + } | |
| 1186 | + | |
| 1187 | + function movefolder($params) { | |
| 1188 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 1189 | + $kt = &$this->KT; | |
| 1190 | + | |
| 1191 | + $response = $kt->move_folder ( $params ['sourcefolderid'], $params ['destfolderid'], $params ['reason'] ); | |
| 1192 | + if ($response ['status_code'] == 0) { | |
| 1193 | + $this->setResponse ( array ('status_code' => 0, 'status' => 'itemupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Folder Moved' ), 'message' => $this->xlate ( 'Folder has been successfully moved' ) ) ); | |
| 1194 | + return true; | |
| 1195 | + } else { | |
| 1196 | + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to move folder' ), 'message' => $this->xlate ( 'Unable to move folder' ) ) ); | |
| 1197 | + return false; | |
| 1198 | + } | |
| 1199 | + } | |
| 1200 | + | |
| 1201 | + function renamefolder($params) { | |
| 1202 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 1203 | + $kt = &$this->KT; | |
| 1204 | + | |
| 1205 | + $response = $kt->rename_folder ( $params ['currentfolderid'], $params ['newname'] ); | |
| 1206 | + if ($response ['status_code'] == 0) { | |
| 1207 | + $this->setResponse ( array ('status_code' => 0, 'status' => 'folderupdated', 'icon' => 'success', 'title' => $this->xlate ( 'Folder Renamed' ), 'message' => $this->xlate ( 'Folder has been successfully renamed' ) ) ); | |
| 1208 | + return true; | |
| 1209 | + } else { | |
| 1210 | + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to rename folder' ), 'message' => $this->xlate ( 'Unable to rename folder' ) ) ); | |
| 1211 | + return false; | |
| 1212 | + } | |
| 1213 | + } | |
| 1214 | + | |
| 1215 | + function addfolder($params) { | |
| 1216 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 1217 | + $kt = &$this->KT; | |
| 1218 | + $this->addDebug ( 'parameters', $params ); | |
| 1219 | + $response = $kt->create_folder ( $params ['currentfolderid'], $params ['newname'] ); | |
| 1220 | + $this->setResponse ( $response ); | |
| 1221 | + return true; | |
| 1222 | + } | |
| 1223 | + | |
| 1224 | + function deletefolder($params) { | |
| 1225 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 1226 | + $kt = &$this->KT; | |
| 1227 | + | |
| 1228 | + $response = $kt->delete_folder ( $params ['folderid'], $params ['reason'] ); | |
| 1229 | + if ($response ['status_code'] == 0) { | |
| 1230 | + $this->setResponse ( array ('status_code' => 0, 'status' => 'folderdeleted', 'icon' => 'success', 'title' => $this->xlate ( 'Folder Deleted' ), 'message' => $this->xlate ( 'Folder has been successfully deleted' ) ) ); | |
| 1231 | + return true; | |
| 1232 | + } else { | |
| 1233 | + $this->setResponse ( array ('status_code' => 1, 'status' => 'error', 'icon' => 'failure', 'title' => $this->xlate ( 'Unable to delete folder' ), 'message' => $this->xlate ( 'Unable to delete folder' ) ) ); | |
| 1234 | + return false; | |
| 1235 | + } | |
| 1236 | + } | |
| 1237 | + | |
| 1238 | + function candeletefolder($arr) { | |
| 1239 | + $this->logTrace((__METHOD__.'('.__FILE__.' '.__LINE__.')'),'Enter Function'); | |
| 1240 | + $kt = &$this->KT; | |
| 1241 | + | |
| 1242 | + $folder = &$kt->get_folder_by_id ( $arr ['folderid'] ); | |
| 1243 | + if (PEAR::isError ( $folder )) { | |
| 1244 | + $this->setResponse ( 'error 1' ); | |
| 1245 | + return false; | |
| 1246 | + } | |
| 1247 | + | |
| 1248 | + $listing = $folder->get_listing ( 1, 'DF' ); | |
| 1249 | + if (count ( $listing ) == 0) { | |
| 1250 | + $this->setResponse ( array ('status_code' => 0, 'candelete' => TRUE ) ); | |
| 1251 | + return true; | |
| 1252 | + } else { | |
| 1253 | + $this->setResponse ( array ('status_code' => 0, 'candelete' => FALSE ) ); | |
| 1254 | + return true; | |
| 1255 | + } | |
| 1256 | + } | |
| 1257 | + | |
| 1258 | + function get_all_files($arr) | |
| 1259 | + { | |
| 1260 | + $kt=&$this->KT; | |
| 1261 | + | |
| 1262 | + $folders = array(); | |
| 1263 | + | |
| 1264 | + if (is_array($arr['folderid'])) { | |
| 1265 | + foreach ($arr['folderid'] as $folder) | |
| 1266 | + { | |
| 1267 | + $folders[] = str_replace('F_', '', $folder); | |
| 1268 | + } | |
| 1269 | + } else { | |
| 1270 | + $folders[] = str_replace('F_', '', $arr['folderid']); | |
| 1271 | + } | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + $this->listOfFiles = array(); | |
| 1275 | + $this->listOfFoldersToBeCreated = array(); | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + foreach ($folders as $folderId) | |
| 1279 | + { | |
| 1280 | + $folder=&$kt->get_folder_by_id($folderId); | |
| 1281 | + if (PEAR::isError($folder)){ | |
| 1282 | + $this->setResponse('error 1'); | |
| 1283 | + return false; | |
| 1284 | + } | |
| 1285 | + | |
| 1286 | + // Note 50 is set here as the level depth, inaccurate | |
| 1287 | + $listing = $folder->get_listing(50, 'DF'); //DF | |
| 1288 | + | |
| 1289 | + if ($folderId == '1') { | |
| 1290 | + $path = 'KnowledgeTree'; | |
| 1291 | + } else { | |
| 1292 | + $path = $folder->get_folder_name(); | |
| 1293 | + } | |
| 1294 | + | |
| 1295 | + $this->addFolderToList($listing, $path); | |
| 1296 | + | |
| 1297 | + } | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + // Sort Array by list of folders to be created in right order | |
| 1301 | + sort($this->listOfFoldersToBeCreated); | |
| 1302 | + | |
| 1303 | + $this->setResponse(array('items'=>$this->listOfFiles, 'folders'=>$this->listOfFoldersToBeCreated)); | |
| 1304 | + return true; | |
| 1305 | + } | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + private function addFolderToList(&$listing, $path) | |
| 1309 | + { | |
| 1310 | + if (!in_array($path, $this->listOfFoldersToBeCreated)) { | |
| 1311 | + $this->listOfFoldersToBeCreated[] = $path; | |
| 1312 | + } | |
| 1313 | + | |
| 1314 | + foreach ($listing as $item) | |
| 1315 | + { | |
| 1316 | + if ($item['item_type'] == 'D') { | |
| 1317 | + $this->listOfFiles[] = array( | |
| 1318 | + 'folderName' => $path, | |
| 1319 | + 'documentId' => $item['id'], | |
| 1320 | + 'filename' => $item['filename'], | |
| 1321 | + 'fullpath' => $path.'/'.$item['filename'] | |
| 1322 | + ); | |
| 1323 | + | |
| 1324 | + } else if ($item['item_type'] == 'F') { | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + $this->addFolderToList($item['items'], $path.'/'.$item['filename']); | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + } | |
| 1332 | + | |
| 1333 | + } | |
| 1334 | + } | |
| 1335 | + | |
| 1336 | + private function convert_size_to_num($size) | |
| 1337 | + { | |
| 1338 | + //This function transforms the php.ini notation for numbers (like '2M') to an integer (2*1024*1024 in this case) | |
| 1339 | + $l = substr($size, -1); | |
| 1340 | + $ret = substr($size, 0, -1); | |
| 1341 | + switch(strtoupper($l)){ | |
| 1342 | + case 'P': | |
| 1343 | + $ret *= 1024; | |
| 1344 | + case 'T': | |
| 1345 | + $ret *= 1024; | |
| 1346 | + case 'G': | |
| 1347 | + $ret *= 1024; | |
| 1348 | + case 'M': | |
| 1349 | + $ret *= 1024; | |
| 1350 | + case 'K': | |
| 1351 | + $ret *= 1024; | |
| 1352 | + break; | |
| 1353 | + } | |
| 1354 | + return $ret; | |
| 1355 | + } | |
| 1356 | + | |
| 1357 | + /* | |
| 1358 | + * Determing the maximum size a file can be to upload | |
| 1359 | + */ | |
| 1360 | + function get_max_fileupload_size() | |
| 1361 | + { | |
| 1362 | + $post_max_size = $this->convert_size_to_num(ini_get('post_max_size')); | |
| 1363 | + $upload_max_filesize = $this->convert_size_to_num(ini_get('upload_max_filesize')); | |
| 1364 | + | |
| 1365 | + if ($upload_max_filesize < 0) { | |
| 1366 | + $max_upload_size = $post_max_size; | |
| 1367 | + } else { | |
| 1368 | + $max_upload_size = min($post_max_size, $upload_max_filesize); | |
| 1369 | + } | |
| 1370 | + $this->setResponse ( array ('status_code' => 0, 'maxsize' => $max_upload_size ) ); | |
| 1371 | + return true; | |
| 1372 | + } | |
| 1373 | + | |
| 1374 | + /** | |
| 1375 | + * Method to get the recently viewed documents and folders. | |
| 1376 | + */ | |
| 1377 | + function get_recently_viewed() | |
| 1378 | + { | |
| 1379 | + $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' ); | |
| 1380 | + $kt = &$this->KT; | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + // Generate Folders List | |
| 1384 | + $returnFoldersArray = array(); | |
| 1385 | + | |
| 1386 | + $folders = $kt->getRecentlyViewedFolders(); | |
| 1387 | + foreach ($folders as $folder) | |
| 1388 | + { | |
| 1389 | + $folderObj = &$kt->get_folder_by_id ( $folder->getFolderId() ); | |
| 1390 | + | |
| 1391 | + $folderArray = array(); | |
| 1392 | + $folderArray['id'] = $folderObj->folderid; | |
| 1393 | + $folderArray['name'] = $folderObj->get_folder_name(); | |
| 1394 | + | |
| 1395 | + $parentIds = explode(',', $folderObj->getParentFolderIds()); | |
| 1396 | + $path = '/F_0'; | |
| 1397 | + | |
| 1398 | + if (count($parentIds) > 0 && $folderObj->getParentFolderIds() != '') { | |
| 1399 | + foreach ($parentIds as $parentId) | |
| 1400 | + { | |
| 1401 | + $path .= '/F_'.$parentId; | |
| 1402 | + } | |
| 1403 | + } | |
| 1404 | + | |
| 1405 | + $path .= '/F_'.$folderObj->folderid; | |
| 1406 | + | |
| 1407 | + $folderArray['path'] = $path; | |
| 1408 | + | |
| 1409 | + $returnFoldersArray[] = $folderArray; | |
| 1410 | + } | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + // Generate Documents List | |
| 1414 | + $returnDocumentArray = array(); | |
| 1415 | + | |
| 1416 | + $items = $kt->getRecentlyViewedDocuments(); | |
| 1417 | + foreach ($items as $item) | |
| 1418 | + { | |
| 1419 | + $document = $kt->get_document_by_id($item->getDocumentId()); | |
| 1420 | + $documentDetail = $document->get_detail(); | |
| 1421 | + | |
| 1422 | + $documentArray = array(); | |
| 1423 | + | |
| 1424 | + $documentArray['id'] = $document->documentid; | |
| 1425 | + $documentArray['contentID'] = $document->documentid; | |
| 1426 | + $documentArray['title'] = $documentDetail['title']; | |
| 1427 | + $documentArray['folderId'] = $documentDetail['folder_id']; | |
| 1428 | + | |
| 1429 | + // Determine Icon Class | |
| 1430 | + $extpos = strrpos ( $documentDetail['filename'], '.' ); | |
| 1431 | + if ($extpos === false) { | |
| 1432 | + $class = 'file-unknown'; | |
| 1433 | + } else { | |
| 1434 | + $class = 'file-' . substr ( $documentDetail['filename'], $extpos + 1 ); // Get Extension without the dot | |
| 1435 | + } | |
| 1436 | + $documentArray['iconCls'] = $class; | |
| 1437 | + | |
| 1438 | + // Determine Icon Path | |
| 1439 | + $folderObj = $kt->get_folder_by_id ( $documentDetail['folder_id']); | |
| 1440 | + $parentIds = explode(',', $folderObj->getParentFolderIds()); | |
| 1441 | + $path = '/F_0'; | |
| 1442 | + if (count($parentIds) > 0 && $folderObj->getParentFolderIds() != '') { | |
| 1443 | + foreach ($parentIds as $parentId) | |
| 1444 | + { | |
| 1445 | + $path .= '/F_'.$parentId; | |
| 1446 | + } | |
| 1447 | + } | |
| 1448 | + $path .= '/F_'.$documentDetail['folder_id']; | |
| 1449 | + | |
| 1450 | + $documentArray['folderPath'] = $path; | |
| 1451 | + | |
| 1452 | + $returnDocumentArray[] = $documentArray; | |
| 1453 | + } | |
| 1454 | + | |
| 1455 | + $this->setResponse(array('documents'=>$returnDocumentArray, 'folders'=>$returnFoldersArray)); | |
| 1456 | + } | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + function get_folder_path($arr) | |
| 1460 | + { | |
| 1461 | + $kt=&$this->KT; | |
| 1462 | + | |
| 1463 | + $folderObj = &$kt->get_folder_by_id ( $arr ['folderId'] ); | |
| 1464 | + if (PEAR::isError ( $folderObj )) { | |
| 1465 | + $this->setError ( "Could not get folder by Id: {$arr['folderId']}" ); | |
| 1466 | + $this->setDebug ( 'FolderError', array ('kt' => $kt, 'folder' => $folderObj ) ); | |
| 1467 | + return false; | |
| 1468 | + } | |
| 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 | + | |
| 1483 | + $this->setResponse ( array ('status_code' => 0, 'folderPath' => $path ) ); | |
| 1484 | + } | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | +} | |
| 1490 | + | |
| 1491 | + | |
| 1492 | +?> | |
| 0 | 1493 | \ No newline at end of file | ... | ... |
webservice/clienttools/services/0.9.1/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 | 27 | \ No newline at end of file | ... | ... |