diff --git a/webservice/clienttools/ajaxhandler.php b/webservice/clienttools/ajaxhandler.php index 67ef31d..d0596a4 100644 --- a/webservice/clienttools/ajaxhandler.php +++ b/webservice/clienttools/ajaxhandler.php @@ -5,14 +5,16 @@ class ajaxHandler{ public $version=NULL; public $auth=NULL; public $request=NULL; - - public function __construct(&$ret=NULL){ + public $kt=NULL; + public $authenticator=NULL; + + public function __construct(&$ret=NULL,&$kt){ // set a local copy of the json request wrapper $this->req=new jsonWrapper(isset($_GET['request'])?$_GET['request']:(isset($_POST['request'])?$_POST['request']:'')); $this->auth=$this->req->jsonArray['auth']; $this->request=$this->req->jsonArray['request']; - - + + // set the response object if(get_class($ret)=='jsonResponseObject'){ $this->ret=&$ret; @@ -20,71 +22,97 @@ class ajaxHandler{ $this->ret=new jsonResponseObject(); } $this->ret->setRequest($this->req->jsonArray); + + if(get_class($kt)=='KTAPI'){ + $this->kt=&$kt; + }else{ + $this->ret->addError('KnowledgeTree Object not Received in '.__CLASS__.' constructor. Quitting.'); + return $this->render(); + } + + // Prepar + $this->loadService('auth'); + $this->authenticator=new auth($this->ret,$this->kt,$this->request,$this->auth); - + //Make sure a token exists before continuing if(!$this->verifyToken())return $this->render(); - - + + if(!$this->verifySession()){ $this->doLogin(); if(!$this->isAuthenticated())return $this->render(); } - + $this->dispatch(); + return $this->render(); } + + public function dispatch(){ + $request=$this->request; + $this->loadService($request['service']); + $service=new $request['service']($this->ret,$this->kt,$this->request,$this->auth); + $this->ret->setTitle($request['service'].'::'.$request['function']); + if(method_exists($service,$request['function'])){ + //$this->ret->setDebug('got here'); + $service->$request['function']($request['parameters']); + }else{ + $this->ret->addError("Service {$request['service']} does not contain the method: {$request['function']}"); + return false; + } + } - + public function loadService($serviceName=NULL){ $version=$this->getVersion(); if(!class_exists($serviceName)){ if(file_exists('services/'.$version.'/'.$serviceName.'.php')){ require_once('services/'.$version.'/'.$serviceName.'.php'); + return true; }else{ throw new Exception('Service could not be found: '.$serviceName); + return false; } } } - + protected function verifyToken(){ $token=isset($this->auth['token'])?$this->auth['token']:NULL; if(!$token){ - $token=md5(rand()*rand()); + $token=md5(rand()*rand()); $this->ret->setStatus('random_token',$token); - return false; + return false; } return true; - } - + } + protected function getVersion(){ if(!$this->version)$this->version=$this->req->getVersion(); return $this->version; } - + protected function verifySession(){ - return false; + return $this->authenticator->pickup_session(); } - + protected function isAuthenticated(){ - + return true; } - + protected function doLogin(){ - $this->loadService('auth'); - $auth=new auth($this->ret); - if(!$auth->login($this->auth)){ + if($this->authenticator->login()){ return true; }else{ $this->ret->addError('Unsuccesful Login'); return false; } } - + public function render(){ echo $this->ret->getJson(); return true; } - + } ?> \ No newline at end of file diff --git a/webservice/clienttools/client_service.php b/webservice/clienttools/client_service.php new file mode 100644 index 0000000..a5c8412 --- /dev/null +++ b/webservice/clienttools/client_service.php @@ -0,0 +1,46 @@ +Response=&$ResponseObject; +// }else{ +// $this->Response=new jsonResponseObject(); +// } + + + $this->Response=&$ResponseObject; + $this->KT=&$KT_Instance; + $this->AuthInfo=&$AuthInfo; + $this->Request=&$Request; + } + + protected function addResponse($name,$value){ + $this->Response->setData($name,$value); + } + + protected function addDebug($name,$value){ + $this->Response->setDebug($name,$value); + } + + protected function setResponse($value){ + $this->Response->overwriteData($value); + } + + protected function addError($message,$code){ + $this->Response->addError($message,$code); + } + + protected function xlate($var=NULL){ + return $var; + } + +} + +?> \ No newline at end of file diff --git a/webservice/clienttools/comms.php b/webservice/clienttools/comms.php index b0da6d3..2a39488 100644 --- a/webservice/clienttools/comms.php +++ b/webservice/clienttools/comms.php @@ -1,7 +1,6 @@ addError($errfile?$errstr:$e->getmessage()); - $GLOBALS['RET']->setDebug('',$errfile?(array('error_number'=>$e,'error_string'=>$errstr,'error_file'=>$errfile,'error_line'=>$errline)):$e); + $GLOBALS['RET']->setDebug($errfile?'ERR':'EXC',$errfile?(array('error_number'=>$e,'error_string'=>$errstr,'error_file'=>$errfile,'error_line'=>$errline)):$e); echo $GLOBALS['RET']->getJson(); exit; }; @@ -27,23 +26,24 @@ function error_handler($e,$errstr=null,$errfile=null,$errline=null){ * Set the error & exception handlers */ $old_exception_handler=set_exception_handler('error_handler'); -$old_error_handler=set_error_handler('error_handler',E_ALL); +$old_error_handler=set_error_handler('error_handler',E_ERROR); /** * Load additional generic libaries */ -require_once("../../config/dmsDefaults.php"); //Interpret the Json Object that was passed include_once('jsonWrapper.php'); include_once('ajaxhandler.php'); +include_once('client_service.php'); //Instantiate base classes +$KT = new KTAPI(); $RET=new jsonResponseObject(); -$handler=new ajaxHandler($RET); +$handler=new ajaxHandler($RET,$KT); diff --git a/webservice/clienttools/comms(2).php b/webservice/clienttools/comms_old.php index 70b3e88..70b3e88 100644 --- a/webservice/clienttools/comms(2).php +++ b/webservice/clienttools/comms_old.php diff --git a/webservice/clienttools/jsonWrapper.php b/webservice/clienttools/jsonWrapper.php index 39ada4c..b48d0f2 100644 --- a/webservice/clienttools/jsonWrapper.php +++ b/webservice/clienttools/jsonWrapper.php @@ -5,6 +5,7 @@ class jsonContentException extends Exception{ } class jsonResponseObject{ + protected $title=''; protected $errors=array(); protected $status=array('session_id'=>'','random_token'=>''); protected $data=array(); @@ -13,6 +14,7 @@ class jsonResponseObject{ public $additional=array(); public $response=array( + 'requestName' =>'', 'errors' =>array( 'hadErrors' =>0 , 'errors' =>array() @@ -39,6 +41,10 @@ class jsonResponseObject{ $this->data[$varName]=$value; } + public function overwriteData($value=NULL){ + $this->data=$value; + } + public function setDebug($varName=NULL,$value=NULL){ $this->debug[$varName]=$value; } @@ -47,8 +53,14 @@ class jsonResponseObject{ $this->request=$request; } + public function setTitle($title=NULL){ + $title=(string)$title; + $this->title=$title; + } + public function getJson(){ $response=array_merge(array( + 'title' =>$this->title, 'errors' =>array( 'hadErrors' =>(count($this->errors)>0?1:0), 'errors' =>$this->errors @@ -64,6 +76,8 @@ class jsonResponseObject{ } } + + class jsonWrapper{ public $raw=''; public $jsonArray=array(); diff --git a/webservice/clienttools/services/3.6.1/auth.php b/webservice/clienttools/services/3.6.1/auth.php index aa9998a..d490458 100644 --- a/webservice/clienttools/services/3.6.1/auth.php +++ b/webservice/clienttools/services/3.6.1/auth.php @@ -1,18 +1,9 @@ ret=&$ret; - }else{ - $this->ret=new jsonResponseObject(); - } - } - - public function login($params){ +class auth extends client_service { + + public function login(){ + $params=$this->AuthInfo; $username=$params['user']; $passhash=$params['passhash']; @@ -21,33 +12,33 @@ class auth{ $session_id=$params['session']; $ip=$_SERVER['REMOTE_ADDR']; $language=isset($params['language'])?$params['language']:'en'; + + $this->Response->setDebug('parameters',$params); setcookie("kt_language", $language, 2147483647, '/'); - - $kt = new KTAPI(); - + $kt =& $this->KT; -// if ($username != 'admin') { -// require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php'); -// -// if (!BaobabKeyUtil::checkIfLicensed(true)) { -// return array('authenticated'=> false, 'message'=> 'license_expired'); -// } -// } + if ($username != 'admin') { + require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php'); + + if (!BaobabKeyUtil::checkIfLicensed(true)) { + return array('authenticated'=> false, 'message'=> 'license_expired'); + } + } $user=$kt->get_user_object_by_username($username); if(!PEAR::isError($user)){ $password=$user->getPassword(); $localPassHash=md5($password.$token); if($localPassHash==$passhash){ - $session=array(); - $this->ret->setDebug('trying to start session with',array('username'=>$username,'password'=>$password)); - $session = $kt->start_session($username, $password, NULL, NULL); + $session=new stdClass(); + $this->Response->setDebug('trying to start session with',array('username'=>$username,'password'=>$password)); + $session = $kt->start_session($username, $params['pass'],NULL,$app_type); if(!PEAR::isError($session)){ - $this->ret->setStatus('session_id',$session); + $this->Response->setStatus('session_id',$session->get_session()); }else{ - $this->ret->setDebug('failed login',$session); + $this->Response->setDebug('failed login',print_r($session,true)); throw new Exception('Unknown Login Error'); return false; } @@ -61,6 +52,21 @@ class auth{ } return true; } + + public function pickup_session(){ + $params=$this->AuthInfo; + $app_type=$params['appType']; + $session_id=$params['session']; + $ip=$_SERVER['REMOTE_ADDR']; + + $session = $this->KT->get_active_session($session_id, $ip, $app_type); + + if (PEAR::isError($session)){ + return false; + } + $this->Response->setStatus('session_id',$session->get_session()); + return true; + } } ?> \ No newline at end of file diff --git a/webservice/clienttools/services/3.6.1/list.service.php b/webservice/clienttools/services/3.6.1/kt.php index 46c50e1..97afde1 100644 --- a/webservice/clienttools/services/3.6.1/list.service.php +++ b/webservice/clienttools/services/3.6.1/kt.php @@ -1,12 +1,5 @@ ktapi=$kt; - } +class kt extends client_service { /** * Get Supported (?) Languages @@ -30,28 +23,24 @@ class clientTools_service_list_361 extends clientTools_service { } } - $this->setResponse('language_info',array('languages' => $languages, 'count' => count($languages), 'defaultLanguage' => $default->defaultLanguage)); + $this->setResponse(array('languages' => $languages, 'count' => count($languages), 'defaultLanguage' => $default->defaultLanguage)); } function get_rootfolder_detail($params){ $params['folderId'] = '1'; - $this->setResponse($this->get_folder_detail($params)); + $this->get_folder_detail($params); } function get_folder_detail($params) { - $kt = &$this->ktapi; -// if (is_array($kt)) -// { -// $this->response= $kt; -// } + $kt = &$this->KT; $folder = &$kt->get_folder_by_id($params['folderId']); if (PEAR::isError($folder)) { - $this->setError(self::ERR_SERVICE_RESOURCE_NOT_FOUND ,"Could not get folder by Id: {$params['folderId']}"); - $this->setDebug('FolderError'.self::ERR_SERVICE_RESOURCE_NOT_FOUND ,array('kt'=>$kt,'folder'=>$folder)); + $this->setError("Could not get folder by Id: {$params['folderId']}"); + $this->setDebug('FolderError',array('kt'=>$kt,'folder'=>$folder)); return; } @@ -65,7 +54,7 @@ class clientTools_service_list_361 extends clientTools_service { $detail['folder_name'] = 'KnowledgeTree'; } - $qtip .= _kt('Folder name').": {$detail['folder_name']}
"; + $qtip .= $this->xlate('Folder name').": {$detail['folder_name']}
"; $class = 'folder'; $permissions = $detail['permissions']; @@ -80,13 +69,13 @@ class clientTools_service_list_361 extends clientTools_service { { case 'W': $canWrite = true; - $perms .= _kt('write, '); + $perms .= $this->xlate('write, '); break; case 'R': - $perms .= _kt('read, '); + $perms .= $this->xlate('read, '); break; case 'A': - $perms .= _kt('add folder, '); + $perms .= $this->xlate('add folder, '); break; } } @@ -98,10 +87,10 @@ class clientTools_service_list_361 extends clientTools_service { } //permissions - $qtip .= _kt('Permissions:') . " {$perms}
"; + $qtip .= $this->xlate('Permissions:') . " {$perms}
"; //comment - $qtip .= $canWrite ? _kt('You may add content to this folder') : _kt('You may not add content to this folder'); + $qtip .= $canWrite ? $this->xlate('You may add content to this folder') : $this->xlate('You may not add content to this folder'); $result[] = array ( @@ -116,130 +105,33 @@ class clientTools_service_list_361 extends clientTools_service { 'qtip'=> $qtip ); - $this->response= $result; + $this->setResponse($result); } -} - - -/* - - - - - function get_folder_detail($params) - { - $kt = &$this->get_ktapi($params['session_id'], $params['application']); - if (is_array($kt)) - { - $this->response= $kt; - } + function get_folder_contents($params){ + $kt=&$this->KT; $params['control'] = 'F_'; $params['node'] = substr($params['node'], strlen($params['control'])); $folder = &$kt->get_folder_by_id($params['node']); - if (PEAR::isError($folder)) - { - $this->response= "folder error {$params['node']}"; + if (PEAR::isError($folder)){ + $this->addError("[error 1] Folder Not Found: {$params['control']}{$params['node']}"); + return false; } - $detail = $folder->get_detail(); - if (PEAR::isError($detail)) - { - $this->response= "detail error {$params['node']}"; - } - - if(strtolower($detail['folder_name']) == 'root folder') { - $detail['folder_name'] = 'KnowledgeTree'; - } - - $qtip .= _kt('Folder name').": {$detail['folder_name']}
"; - $class = 'folder'; - - $permissions = $detail['permissions']; - $perms = ''; - //default write permissions to false - $canWrite = false; - - //iterate through the permissions and convert to human-readable - for ($j = 0; $j < strlen($permissions); $j++) - { - switch (strtoupper($permissions{$j})) - { - case 'W': - $canWrite = true; - $perms .= _kt('write, '); - break; - case 'R': - $perms .= _kt('read, '); - break; - case 'A': - $perms .= _kt('add folder, '); - break; - } - } - - //now chop off trailing ', ' if any - if (strlen($perms) > 2) - { - $perms = substr($perms, 0, strlen($perms)-2); - } - - //permissions - $qtip .= _kt('Permissions:') . " {$perms}
"; - - //comment - $qtip .= $canWrite ? _kt('You may add content to this folder') : _kt('You may not add content to this folder'); - - $result[] = array - ( - 'text' => $detail['folder_name'], - 'id' => $params['control'] . $params['node'], - 'filename' => $detail['folder_name'], - 'cls' => 'folder', - 'leaf' => false, - 'document_type' => '', - 'item_type' => 'F', - 'permissions' => $permissions, - 'qtip'=> $qtip - ); - - $this->response= $result; - } - - function get_folder_contents($arr) - { - $kt = &$this->get_ktapi($arr['session_id'], $arr['application']); - - if (is_array($kt)) - { - $this->response= $kt; - } - - $arr['control'] = 'F_'; - $arr['node'] = substr($arr['node'], strlen($arr['control'])); - - $folder = &$kt->get_folder_by_id($arr['node']); - if (PEAR::isError($folder)) - { - $response = 'error'; - - $this->response= 'error 1'; - } - - $types = (isset($arr['types']) ? $arr['types'] : 'DF'); + $types = (isset($params['types']) ? $params['types'] : 'DF'); $listing = $folder->get_listing(1, $types); - $result = ListController::_processListing($listing, 'folderContents', $arr); + $result = $this->_processListing($listing, 'folderContents', $params); - $this->response= $result; + $this->setResponse($result); } - private function _processListing($listing, $type, $arr) - { + + private function _processListing($listing, $type, $arr){ $result = array(); $methodToIncludeItem = '_processItemInclusion_'.$type; @@ -269,13 +161,13 @@ class clientTools_service_list_361 extends clientTools_service { { case 'W': $canWrite = true; - $perms .= _kt('write, '); + $perms .= $this->xlate('write, '); break; case 'R': - $perms .= _kt('read, '); + $perms .= $this->xlate('read, '); break; case 'A': - $perms .= _kt('add folder, '); + $perms .= $this->xlate('add folder, '); break; // default: // $perms .= strtoupper($permissions{$j}); @@ -292,14 +184,14 @@ class clientTools_service_list_361 extends clientTools_service { //folders if ($itemType == 'F') { - $qtip .= _kt('Folder name').": {$filename}
"; + $qtip .= $this->xlate('Folder name').": {$filename}
"; $class = 'folder'; //permissions - $qtip .= _kt('Permissions:') . " {$perms}
"; + $qtip .= $this->xlate('Permissions:') . " {$perms}
"; //comment - $qtip .= $canWrite ? _kt('You may add content to this folder') : _kt('You may not add content to this folder'); + $qtip .= $canWrite ? $this->xlate('You may add content to this folder') : $this->xlate('You may not add content to this folder'); } //documents @@ -331,19 +223,19 @@ class clientTools_service_list_361 extends clientTools_service { else { //filename - $qtip .= _kt('Filename') . ": {$filename}
"; + $qtip .= $this->xlate('Filename') . ": {$filename}
"; //size - $qtip .= _kt('File Size') . ": " . fsize_desc($item['filesize']) . "
"; + $qtip .= $this->xlate('File Size') . ": " . fsize_desc($item['filesize']) . "
"; //last modified - $qtip .= _kt('Modified') . ": {$item['modified_date']}
"; + $qtip .= $this->xlate('Modified') . ": {$item['modified_date']}
"; //owner - $qtip .= _kt('Owner') . ": {$item['created_by']}
"; + $qtip .= $this->xlate('Owner') . ": {$item['created_by']}
"; //version - $qtip .= _kt('Version') . ": {$item['version']}
"; + $qtip .= $this->xlate('Version') . ": {$item['version']}
"; //immutability if (bool2str(strtolower($item['is_immutable'])) == 'true') @@ -355,49 +247,50 @@ class clientTools_service_list_361 extends clientTools_service { //status, i.e. checked out or not, or immutable if ($immutable) { - $qtip .= _kt('Status: Immutable') . '
'; + $qtip .= $this->xlate('Status: Immutable') . '
'; } else if (strtolower($item['checked_out_by']) != 'n/a' && ($item['checked_out_by'] != '')) { - $qtip .= _kt('Status: Checked out by') . " {$item['checked_out_by']}
"; + $qtip .= $this->xlate('Status: Checked out by') . " {$item['checked_out_by']}
"; } else { - $qtip .= _kt('Status: Available') . '
'; + $qtip .= $this->xlate('Status: Available') . '
'; } //permissions - $qtip .= _kt('Permissions:') . " {$perms}
"; + $qtip .= $this->xlate('Permissions:') . " {$perms}
"; //immutable if($immutable) { - $qtip .= _kt('This document is not editable'); + $qtip .= $this->xlate('This document is not editable'); } else if ($canWrite) { - $qtip .= _kt('You may edit this document'); + $qtip .= $this->xlate('You may edit this document'); } else { - $qtip .= _kt('This document is not editable'); + $qtip .= $this->xlate('This document is not editable'); } } }//end of if for files if($includeMe) { - $result[] = ListController::$methodToIncludeItem($item, $class, $qtip); + $result[] = $this->$methodToIncludeItem($item, $class, $qtip); } } - $this->response= $result; + return $result; } + private function _processItemInclusion_folderContents($item, $class, $qtip) { - $this->response= array ( + return array ( 'text' => htmlspecialchars($item['title']), 'originaltext' => $item['title'], 'id' => ($item['item_type'] == 'F' ? $item['item_type']."_" : "").$item['id'], @@ -415,7 +308,7 @@ class clientTools_service_list_361 extends clientTools_service { private function _processItemInclusion_search($item, $class, $qtip) { - $this->response= array ( + return array ( 'text' => htmlspecialchars($item['title']), 'originaltext' => $item['title'], 'id' => $item['document_id'], @@ -431,27 +324,23 @@ class clientTools_service_list_361 extends clientTools_service { ); } + + public function get_metadata($params) { - function get_metadata($arr) { + $kt = &$this->KT; - $kt = &$this->get_ktapi($arr['session_id'], $arr['application']); - if (is_array($kt)) - { - $this->response= $kt; - } - - $document_id = (int)$arr['document_id']; + $document_id = (int)$params['document_id']; if($document_id > 0) { - $document = $kt->get_document_by_id($arr['document_id']); + $document = $kt->get_document_by_id($params['document_id']); $detail = $document->get_metadata(); $document_detail = $document->get_detail(); $title = $document_detail['title']; $document_type = $document_detail['document_type']; } else { - if(isset($arr['document_type'])) { - $document_type = $arr['document_type']; + if(isset($params['document_type'])) { + $document_type = $params['document_type']; } else { $document_type = 'Default'; } @@ -467,14 +356,14 @@ class clientTools_service_list_361 extends clientTools_service { // Commented out for timebeing - will be used by 'Save in Format' - if (isset($arr['extensions'])) { + if (isset($params['extensions'])) { $fileParts = pathinfo($document_detail['filename']); - $items[] = array("name" => "__document_extension", "index" => 0, "value" => strtolower($fileParts['extension']), "control_type" => "lookup", "selection" => explode(',', str_replace('.', '', $arr['extensions']))); + $items[] = array("name" => "__document_extension", "index" => 0, "value" => strtolower($fileParts['extension']), "control_type" => "lookup", "selection" => explode(',', str_replace('.', '', $params['extensions']))); } - $document_types = $this->get_documenttypes($arr); + $document_types = $this->get_documenttypes($params); $json_document_types = array(); foreach($document_types['items'] as $val) { $json_document_types[] = $val['name']; @@ -506,18 +395,15 @@ class clientTools_service_list_361 extends clientTools_service { } - $this->response= array('id' => $title, 'items' => $items, 'count' => count($items)); + $this->setResponse(array('id' => $title, 'items' => $items, 'count' => count($items))); } - function get_documenttypes($arr) { - $kt = &$this->get_ktapi($arr['session_id'], $arr['application']); - if (is_array($kt)) - { - $this->response= $kt; - } + public function get_documenttypes($params) { + + $kt = &$this->KT; $detail = $kt->get_documenttypes(); $result = array(); @@ -526,50 +412,39 @@ class clientTools_service_list_361 extends clientTools_service { if(strtolower(substr($detail[$i], -5)) != 'email') { $items[] = array( - 'name' => $detail[$i] + 'name' => $detail[$i] ); } } - $this->response= array('items' => $items, 'count' => count($items)); - - + $this->setResponse(array('items' => $items, 'count' => count($items))); } - function update_document_type($arr) { - $kt = &$this->get_ktapi($arr['session_id'], $arr['application']); - if (is_array($kt)) - { - $this->response= $kt; - } - $document_id = (int)$arr['document_id']; + function update_document_type($params) { + $kt = &$this->KT; + $document_id = (int)$params['document_id']; if($document_id > 0) { $document = $kt->get_document_by_id($document_id); - $document->change_document_type($arr['document_type']); - $this->response= array('status_code' => 0); - + $document->change_document_type($params['document_type']); + $this->setResponse(array('status_code' => 0)); + return true; + + }else{ + $this->addError("Invalid document Id : {$document_id}"); + $this->setResponse(array('status_code' => 1)); + return false; } - $this->response= array('status_code' => 1); - } + function download_document($params) { - function debug($str) { - $this->response= true; - if(!is_resource($this->dfp)) { - $this->dfp = fopen("./debug.log", "a+"); - } - fwrite($this->dfp, strftime("[DEBUG %Y-%m-%d %H:%M:%S] ").$str."\r\n"); - } - - function download_document($params) - { - - $kt = &$this->get_ktapi($params['session_id'], $params['application']); - if (is_array($kt)) - { - $this->response= array('status_code' => 1); - } + $kt=&$this->KT; + $params['session_id']=$params['session_id']?$params['session_id']:$this->AuthInfo['session']; + $params['app_type']=$params['app_type']?$params['app_type']:$this->AuthInfo['appType']; + + $this->addDebug('parameters',$params); + + $session_id=$params['session_id']; $document = &$kt->get_document_by_id($params['document_id']); @@ -580,14 +455,16 @@ class clientTools_service_list_361 extends clientTools_service { $response['message'] = $document->getMessage(); $this->debug("download_document - cannot get $document_id - " . $document->getMessage(), $session_id); - $this->response= new SOAP_Value('$this->response=',"{urn:$this->namespace}kt_response", $response); + $this->setResponse(new SOAP_Value('$this->response=',"{urn:$this->namespace}kt_response", $response)); + return; } $result = $document->download(); if (PEAR::isError($result)) { $response['message'] = $result->getMessage(); - $this->response= array('status_code' => 1, 'message' => $result->getMessage()); + $this->setResponse(array('status_code' => 1, 'message' => $result->getMessage())); + return; } $session = &$kt->get_session(); @@ -599,32 +476,37 @@ class clientTools_service_list_361 extends clientTools_service { $response['status_code'] = 0; $response['message'] = $url; $response['filename'] = $docname; - $this->response= $response; + $this->setResponse($response); } - function checkout_document($params) - { - //$this->debug("checkout_document('$session_id',$document_id,'$reason')"); - + + /** + * Checkout a Document + * params contains: + * document_id the id of the document + * reason the checkout reason + * + * @param array $params + * + */ + function checkout_document($params){ $responseType = 'kt_response'; - - $kt = &$this->get_ktapi($params['session_id'], $params['application']); - if (is_array($kt)) - { - $this->response= array('status_code' => 1); - } + $kt=&$this->KT; $document = &$kt->get_document_by_id($params['document_id']); if (PEAR::isError($document)) { - $this->debug("checkout_document - cannot get documentid {$params['document_id']} - " . $document->getMessage()); - $this->response= array('status_code' => 1, 'message' => $document->getMessage()); + $this->addError("checkout_document - cannot get documentid {$params['document_id']} - " . $document->getMessage()); + $this->setResponse(array('status_code' => 1, 'message' => $document->getMessage())); + return; } $result = $document->checkout($params['reason']); if (PEAR::isError($result)) { - $this->response= array('status_code' => 1, 'message' => $result->getMessage()); + $this->addError($result->getMessage()); + $this->setResponse(array('status_code' => 1, 'message' => $result->getMessage())); + return; } $url = ''; @@ -636,12 +518,69 @@ class clientTools_service_list_361 extends clientTools_service { $url = $download_manager->allow_download($document); } - $this->response= array('status_code' => 0, 'message' => $url); + $this->setResponse(array('status_code' => 0, 'message' => $url)); } - function add_document_with_metadata($arr) - { + /** + * Checkin Document //TODO: Find out how upload works + * params contains: + * document_id + * filename + * reason + * tempfilename + * + * @param array $params + */ + function checkin_document($params){ + $session_id = $this->AuthInfo['session']; + $document_id = $params['document_id']; + $filename = $params['filename']; + $reason = $params['reason']; + $tempfilename = $params['tempfilename']; + $application = $this->AuthInfo['appType']; + + $this->addDebug('Checkin',"checkin_document('$session_id',$document_id,'$filename','$reason','$tempfilename', '$application')"); + $kt = &$this->KT; + + // we need to add some security to ensure that people don't frig the checkin process to access restricted files. + // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome. + $upload_manager = new KTUploadManager(); + if (!$upload_manager->is_valid_temporary_file($tempfilename)) + { + $this->setResponse(array('status_code' => 12)); + return; + } + + $document = &$kt->get_document_by_id($document_id); + if (PEAR::isError($document)) + { + $this->setResponse(array('status_code' => 13)); + } + + // checkin + $result = $document->checkin($filename, $reason, $tempfilename, false); + if (PEAR::isError($result)) + { + $this->setResponse(array('status_code' => 14)); + } + + // get status after checkin + //$this->response= $this->get_document_detail($session_id, $document_id); + $detail = $document->get_detail(); + $detail['status_code'] = 0; + $detail['message'] = ''; + + $this->setResponse($detail); + } + + + /** + * Upload a document + * + * @param unknown_type $arr + */ + function add_document_with_metadata($arr){ $session_id = $arr['session_id']; //error_reporting(E_ALL); $metadata = array(); @@ -680,7 +619,7 @@ class clientTools_service_list_361 extends clientTools_service { $this->response= $update_result; } - $kt = &$this->get_ktapi($arr['session_id'], $arr['application']); + $kt = &$this->KT; if (is_array($kt)) { $this->response= array('status_code' => 1); @@ -703,6 +642,33 @@ class clientTools_service_list_361 extends clientTools_service { $this->response= array('status_code' => 0, 'document_id' => $document_id, 'content_id' => $content_id); } +} + + +/* + + + + + + + + + + + + + function debug($str) { + $this->response= true; + if(!is_resource($this->dfp)) { + $this->dfp = fopen("./debug.log", "a+"); + } + fwrite($this->dfp, strftime("[DEBUG %Y-%m-%d %H:%M:%S] ").$str."\r\n"); + } + + + + function add_document_params($params) { $session_id = $params['session_id']; @@ -714,7 +680,7 @@ class clientTools_service_list_361 extends clientTools_service { $application = $params['application']; $this->debug('Entered add_document'); - $kt = &$this->get_ktapi($session_id, $application); + $kt = &$this->get$this->xlateapi($session_id, $application); if (is_array($kt)) { $this->response= array('status_code' => 1); @@ -756,7 +722,7 @@ class clientTools_service_list_361 extends clientTools_service { function add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $application) { $this->debug('Entered add_document'); - $kt = &$this->get_ktapi($session_id, $application); + $kt = &$this->get$this->xlateapi($session_id, $application); if (is_array($kt)) { $this->response= array('status_code' => 1); @@ -794,55 +760,10 @@ class clientTools_service_list_361 extends clientTools_service { } - function checkin_document($params) - { - $session_id = $params['session_id']; - $document_id = $params['document_id']; - $filename = $params['filename']; - $reason = $params['reason']; - $tempfilename = $params['tempfilename']; - $application = $params['application']; - - $this->debug("checkin_document('$session_id',$document_id,'$filename','$reason','$tempfilename', '$application')"); - $kt = &$this->get_ktapi($session_id, $application ); - if (is_array($kt)) - { - $this->response= array('status_code' => 11); - } - - // we need to add some security to ensure that people don't frig the checkin process to access restricted files. - // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome. - $upload_manager = new KTUploadManager(); - if (!$upload_manager->is_valid_temporary_file($tempfilename)) - { - $this->response= array('status_code' => 12); - } - - $document = &$kt->get_document_by_id($document_id); - if (PEAR::isError($document)) - { - $this->response= array('status_code' => 13); - } - - // checkin - $result = $document->checkin($filename, $reason, $tempfilename, false); - if (PEAR::isError($result)) - { - $this->response= array('status_code' => 14); - } - - // get status after checkin - //$this->response= $this->get_document_detail($session_id, $document_id); - $detail = $document->get_detail(); - $detail['status_code'] = 0; - $detail['message'] = ''; - - $this->response= $detail; - } function delete_document($session_id, $document_id, $reason, $application) { - $kt = &$this->get_ktapi($session_id, $application ); + $kt = &$this->get$this->xlateapi($session_id, $application ); if (is_array($kt)) { $this->response= array('status_code' => 1); @@ -869,7 +790,7 @@ class clientTools_service_list_361 extends clientTools_service { function update_document_metadata($session_id, $document_id, $metadata, $application, $sysdata=null) { $this->debug('entered update_document_metadata'); - $kt = &$this->get_ktapi($session_id, $application ); + $kt = &$this->get$this->xlateapi($session_id, $application ); $responseType = 'kt_response'; if ($this->version >= 2) { @@ -962,7 +883,7 @@ class clientTools_service_list_361 extends clientTools_service { function search($arr) { - $kt = &$this->get_ktapi($arr['session_id'], $arr['application']); + $kt = &$this->get$this->xlateapi($arr['session_id'], $arr['application']); if (is_array($kt)) { @@ -977,11 +898,11 @@ class clientTools_service_list_361 extends clientTools_service { $result[] = array ( - 'text' => _kt("No results found"), + 'text' => $this->xlate("No results found"), 'id' => ($listing[$i]['item_type'] == 'F' ? $listing[$i]['item_type']."_" : "").$listing[$i]['id'], 'leaf' => true, 'relevance' => 0, - 'qtip'=> _kt("Please retry your search") + 'qtip'=> $this->xlate("Please retry your search") ); } else { $result = array_slice($result, 0, 200); @@ -1026,7 +947,7 @@ class clientTools_service_list_361 extends clientTools_service { $this->response= $update_result; } - $kt = &$this->get_ktapi($arr['session_id']); + $kt = &$this->get$this->xlateapi($arr['session_id']); if (is_array($kt)) { $this->response= $kt; @@ -1050,7 +971,7 @@ class clientTools_service_list_361 extends clientTools_service { function check_document_title($arr) { - $kt = &$this->get_ktapi($arr['session_id'], $arr['application'] ); + $kt = &$this->get$this->xlateapi($arr['session_id'], $arr['application'] ); if (is_array($kt)) @@ -1079,7 +1000,7 @@ class clientTools_service_list_361 extends clientTools_service { { //$this->debug("undo_document_checkout({$params['session_id']}, {$params['document_id']}, {$params['reason']})"); - $kt = &$this->get_ktapi($params['session_id'], $params['application'] ); + $kt = &$this->get$this->xlateapi($params['session_id'], $params['application'] ); if (is_array($kt)) { $this->response= array('status_code' => 1); @@ -1104,7 +1025,7 @@ class clientTools_service_list_361 extends clientTools_service { function get_users_groups($params) { - $kt = &$this->get_ktapi($params['session_id'],$params['application'] ); + $kt = &$this->get$this->xlateapi($params['session_id'],$params['application'] ); if (is_array($kt)) { $this->response= array('status_code' => 1); @@ -1145,7 +1066,7 @@ class clientTools_service_list_361 extends clientTools_service { function send_email($params) { - $kt = &$this->get_ktapi($params['session_id'], $params['application'] ); + $kt = &$this->get$this->xlateapi($params['session_id'], $params['application'] ); if (is_array($kt)) { $this->response= array('status_code' => 1); @@ -1212,7 +1133,7 @@ class clientTools_service_list_361 extends clientTools_service { function is_latest_version($params) { - $kt = &$this->get_ktapi($params['session_id'], $params['application']); + $kt=&$this->KT; if (is_array($kt)) @@ -1231,7 +1152,7 @@ class clientTools_service_list_361 extends clientTools_service { function check_permission($params) { - $kt = &$this->get_ktapi($params['session_id'], $params['application']); + $kt=&$this->KT; if (is_array($kt)) @@ -1260,7 +1181,7 @@ class clientTools_service_list_361 extends clientTools_service { function renamefolder($params) { - $kt = &$this->get_ktapi($params['session_id'], $params['application'] ); + $kt = &$this->get$this->xlateapi($params['session_id'], $params['application'] ); if (is_array($kt)) { $this->response= array('status_code' => 1); @@ -1269,16 +1190,16 @@ class clientTools_service_list_361 extends clientTools_service { $response = $kt->rename_folder($params['currentfolderid'], $params['newname']); if ($response['status_code'] == 0) { - $this->response= array('status_code' => 0, 'status'=>'folderupdated', 'icon'=>'success', 'title'=>_kt('Folder Renamed'), 'message'=>_kt('Folder has been successfully renamed')); + $this->response= array('status_code' => 0, 'status'=>'folderupdated', 'icon'=>'success', 'title'=>$this->xlate('Folder Renamed'), 'message'=>$this->xlate('Folder has been successfully renamed')); } else { - $this->response= array('status_code' => 1, 'status'=>'error', 'icon'=>'failure', 'title'=>_kt('Unable to rename folder'), 'message'=>_kt('Unable to rename folder')); //$response['message'] + $this->response= array('status_code' => 1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to rename folder'), 'message'=>$this->xlate('Unable to rename folder')); //$response['message'] } } function addfolder($params) { - $kt = &$this->get_ktapi($params['session_id'], $params['application'] ); + $kt = &$this->get$this->xlateapi($params['session_id'], $params['application'] ); if (is_array($kt)) { $this->response= array('status_code' => 1); @@ -1288,16 +1209,16 @@ class clientTools_service_list_361 extends clientTools_service { $response = $kt->create_folder($params['currentfolderid'], $params['newname']); if ($response['status_code'] == 0) { - $this->response= array('status_code' => 0, 'status'=>'folderupdated', 'icon'=>'success', 'title'=>_kt('Folder Created'), 'message'=>_kt('Folder has been successfully created'), 'id' =>$response['results']['id']); //$params['newname']);// + $this->response= array('status_code' => 0, 'status'=>'folderupdated', 'icon'=>'success', 'title'=>$this->xlate('Folder Created'), 'message'=>$this->xlate('Folder has been successfully created'), 'id' =>$response['results']['id']); //$params['newname']);// } else { - $this->response= array('status_code' => 1, 'status'=>'error', 'icon'=>'failure', 'title'=>_kt('Unable to create folder'), 'message'=>_kt('Unable to create folder')); //$response['message'] + $this->response= array('status_code' => 1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to create folder'), 'message'=>$this->xlate('Unable to create folder')); //$response['message'] } } function deletefolder($params) { - $kt = &$this->get_ktapi($params['session_id'], $params['application'] ); + $kt = &$this->get$this->xlateapi($params['session_id'], $params['application'] ); if (is_array($kt)) { $this->response= array('status_code' => 1); @@ -1306,16 +1227,16 @@ class clientTools_service_list_361 extends clientTools_service { $response = $kt->delete_folder($params['folderid'], 'Deleted from office addin'); if ($response['status_code'] == 0) { - $this->response= array('status_code' => 0, 'status'=>'folderdeleted', 'icon'=>'success', 'title'=>_kt('Folder Deleted'), 'message'=>_kt('Folder has been successfully deleted')); + $this->response= array('status_code' => 0, 'status'=>'folderdeleted', 'icon'=>'success', 'title'=>$this->xlate('Folder Deleted'), 'message'=>$this->xlate('Folder has been successfully deleted')); } else { - $this->response= array('status_code' => 1, 'status'=>'error', 'icon'=>'failure', 'title'=>_kt('Unable to delete folder'), 'message'=>_kt('Unable to delete folder')); //$response['message'] + $this->response= array('status_code' => 1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to delete folder'), 'message'=>$this->xlate('Unable to delete folder')); //$response['message'] } } function candeletefolder($arr) { - $kt = &$this->get_ktapi($arr['session_id'], $arr['application']); + $kt = &$this->get$this->xlateapi($arr['session_id'], $arr['application']); if (is_array($kt)) { diff --git a/webservice/clienttools/services/3.6.1/server.service.php b/webservice/clienttools/services/3.6.1/server.php index d4121cb..160e565 100644 --- a/webservice/clienttools/services/3.6.1/server.service.php +++ b/webservice/clienttools/services/3.6.1/server.php @@ -1,10 +1,12 @@ addResponse('pong',time()); + } public function getToken(){ @@ -13,11 +15,8 @@ class clientTools_service_server_361 extends clientTools_service{ public function phpInfo(){ ob_start(); phpinfo(); - $this->response['phpinfo']=ob_get_clean(); + $this->addResponse('phpinfo',ob_get_clean()); } - public function getServiceObject(){ - $this->response['serviceobject']=new clientTools_service_server_361(&$this->kt,&$this->session,&$this->session_id); - } } ?> \ No newline at end of file