Commit ef78e08a4cc44324ccdb14098f4e9a39dc6494e1

Authored by Mark Holtzhausen
1 parent bd5daf64

Updated webservice/clientools & ktwebservice for Karoo Integration

ktwebservice/1-20090903194035 0 → 100644
  1 +<?xml version="1.0"?>
  2 +<Document xmlns="http://www.evolus.vn/Namespace/Pencil"><Properties/><Pages><Page><Properties><Property name="name">Acorn Layout</Property><Property name="id">1247050268296_4354</Property><Property name="width">1024</Property><Property name="height">768</Property><Property name="dimBackground">false</Property></Properties><Content><g xmlns="http://www.w3.org/2000/svg" p:type="Shape" xmlns:p="http://www.evolus.vn/Namespace/Pencil" p:def="Evolus.Common:RoundedRect" transform="matrix(1, 0, 0, 1, 0, 0)" p:locked="true"><p:metadata><p:property name="box"><![CDATA[1030,770]]></p:property><p:property name="withBlur"><![CDATA[false]]></p:property><p:property name="radius"><![CDATA[7,0]]></p:property><p:property name="textPadding"><![CDATA[0,10]]></p:property><p:property name="fillColor"><![CDATA[#336699FF]]></p:property><p:property name="strokeColor"><![CDATA[#000000FF]]></p:property><p:property name="strokeStyle"><![CDATA[0|]]></p:property><p:property name="textContent"><![CDATA[]]></p:property><p:property name="textFont"><![CDATA[Arial|normal|normal|12px|none]]></p:property><p:property name="textColor"><![CDATA[#FFFFFFFF]]></p:property><p:property name="textAlign"><![CDATA[1,1]]></p:property></p:metadata>
  3 +
  4 + <defs>
  5 + <rect width="1030" height="770" rx="7" ry="7" x="0" y="0" style="stroke-width: 0pt; fill: rgb(51, 102, 153); fill-opacity: 1; stroke: rgb(0, 0, 0); stroke-opacity: 1;" p:name="rrRect" id="rrRect11247050298197" transform="translate(0)"/>
  6 + <filter height="1.2558399" y="-0.12792" width="1.06396" x="-0.03198" p:name="shadingFilter" id="shadingFilter11247050298197">
  7 + <feGaussianBlur stdDeviation="1" in="SourceAlpha"/>
  8 + </filter>
  9 + </defs>
  10 + <use xlink:href="#rrRect11247050298197" xmlns:xlink="http://www.w3.org/1999/xlink" transform="translate(2, 2)" p:filter="url(#shadingFilter11247050298197)" style="opacity: 0.5; visibility: hidden;" p:heavy="true" p:name="bgCopy" id="bgCopy11247050298197"/>
  11 + <use xlink:href="#rrRect11247050298197" xmlns:xlink="http://www.w3.org/1999/xlink"/>
  12 + <foreignObject x="10" y="385" width="1010" height="0" p:name="text" id="text11247050298197" style="font-family: Arial; font-size: 12px; font-weight: normal; font-style: normal; text-decoration: none; fill: rgb(255, 255, 255); fill-opacity: 1; color: rgb(255, 255, 255); opacity: 1; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml"/></foreignObject><path id="text11247050298197_underline" style="fill: none; stroke-width: 1px; visibility: hidden;"/>
  13 + </g><g xmlns="http://www.w3.org/2000/svg" p:type="Shape" xmlns:p="http://www.evolus.vn/Namespace/Pencil" p:def="Evolus.Common:RoundedRect" transform="matrix(1, 0, 0, 1, 13, 92)"><p:metadata><p:property name="box"><![CDATA[210,550]]></p:property><p:property name="withBlur"><![CDATA[false]]></p:property><p:property name="radius"><![CDATA[7,0]]></p:property><p:property name="textPadding"><![CDATA[0,10]]></p:property><p:property name="fillColor"><![CDATA[#FFFFFFFF]]></p:property><p:property name="strokeColor"><![CDATA[#000000FF]]></p:property><p:property name="strokeStyle"><![CDATA[0|]]></p:property><p:property name="textContent"><![CDATA[]]></p:property><p:property name="textFont"><![CDATA[Arial|normal|normal|12px|none]]></p:property><p:property name="textColor"><![CDATA[#FFFFFFFF]]></p:property><p:property name="textAlign"><![CDATA[1,1]]></p:property></p:metadata>
  14 +
  15 + <defs>
  16 + <rect width="210" height="550" rx="7" ry="7" x="0" y="0" style="stroke-width: 0pt; fill: rgb(255, 255, 255); fill-opacity: 1; stroke: rgb(0, 0, 0); stroke-opacity: 1;" p:name="rrRect" id="rrRect21247050338773" transform="translate(0)"/>
  17 + <filter height="1.2558399" y="-0.12792" width="1.06396" x="-0.03198" p:name="shadingFilter" id="shadingFilter21247050338773">
  18 + <feGaussianBlur stdDeviation="1" in="SourceAlpha"/>
  19 + </filter>
  20 + </defs>
  21 + <use xlink:href="#rrRect21247050338773" xmlns:xlink="http://www.w3.org/1999/xlink" transform="translate(2, 2)" p:filter="url(#shadingFilter21247050338773)" style="opacity: 0.5; visibility: hidden;" p:heavy="true" p:name="bgCopy" id="bgCopy21247050338773"/>
  22 + <use xlink:href="#rrRect21247050338773" xmlns:xlink="http://www.w3.org/1999/xlink"/>
  23 + <foreignObject x="10" y="275" width="190" height="0" p:name="text" id="text21247050338773" style="font-family: Arial; font-size: 12px; font-weight: normal; font-style: normal; text-decoration: none; fill: rgb(255, 255, 255); fill-opacity: 1; color: rgb(255, 255, 255); opacity: 1; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml"/></foreignObject><path id="text21247050338773_underline" style="fill: none; stroke-width: 1px; visibility: hidden;"/>
  24 + </g><g xmlns="http://www.w3.org/2000/svg" p:type="Shape" xmlns:p="http://www.evolus.vn/Namespace/Pencil" p:def="Evolus.Common:RoundedRect" transform="matrix(1, 0, 0, 1, 235, 90)"><p:metadata><p:property name="box"><![CDATA[560,550]]></p:property><p:property name="withBlur"><![CDATA[false]]></p:property><p:property name="radius"><![CDATA[7,0]]></p:property><p:property name="textPadding"><![CDATA[0,10]]></p:property><p:property name="fillColor"><![CDATA[#FFFFFFFF]]></p:property><p:property name="strokeColor"><![CDATA[#000000FF]]></p:property><p:property name="strokeStyle"><![CDATA[0|]]></p:property><p:property name="textContent"><![CDATA[]]></p:property><p:property name="textFont"><![CDATA[Arial|normal|normal|12px|none]]></p:property><p:property name="textColor"><![CDATA[#FFFFFFFF]]></p:property><p:property name="textAlign"><![CDATA[1,1]]></p:property></p:metadata>
  25 +
  26 + <defs>
  27 + <rect width="560" height="550" rx="7" ry="7" x="0" y="0" style="stroke-width: 0pt; fill: rgb(255, 255, 255); fill-opacity: 1; stroke: rgb(0, 0, 0); stroke-opacity: 1;" p:name="rrRect" id="rrRect31247050400981" transform="translate(0)"/>
  28 + <filter height="1.2558399" y="-0.12792" width="1.06396" x="-0.03198" p:name="shadingFilter" id="shadingFilter31247050400981">
  29 + <feGaussianBlur stdDeviation="1" in="SourceAlpha"/>
  30 + </filter>
  31 + </defs>
  32 + <use xlink:href="#rrRect31247050400981" xmlns:xlink="http://www.w3.org/1999/xlink" transform="translate(2, 2)" p:filter="url(#shadingFilter31247050400981)" style="opacity: 0.5; visibility: hidden;" p:heavy="true" p:name="bgCopy" id="bgCopy31247050400981"/>
  33 + <use xlink:href="#rrRect31247050400981" xmlns:xlink="http://www.w3.org/1999/xlink"/>
  34 + <foreignObject x="10" y="275" width="540" height="0" p:name="text" id="text31247050400981" style="font-family: Arial; font-size: 12px; font-weight: normal; font-style: normal; text-decoration: none; fill: rgb(255, 255, 255); fill-opacity: 1; color: rgb(255, 255, 255); opacity: 1; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml"/></foreignObject><path id="text31247050400981_underline" style="fill: none; stroke-width: 1px; visibility: hidden;"/>
  35 + </g><g xmlns="http://www.w3.org/2000/svg" p:type="Shape" xmlns:p="http://www.evolus.vn/Namespace/Pencil" p:def="Evolus.Common:RoundedRect" transform="matrix(1, 0, 0, 1, 803, 92)"><p:metadata><p:property name="box"><![CDATA[210,550]]></p:property><p:property name="withBlur"><![CDATA[false]]></p:property><p:property name="radius"><![CDATA[7,0]]></p:property><p:property name="textPadding"><![CDATA[0,10]]></p:property><p:property name="fillColor"><![CDATA[#FFFFFFFF]]></p:property><p:property name="strokeColor"><![CDATA[#000000FF]]></p:property><p:property name="strokeStyle"><![CDATA[0|]]></p:property><p:property name="textContent"><![CDATA[]]></p:property><p:property name="textFont"><![CDATA[Arial|normal|normal|12px|none]]></p:property><p:property name="textColor"><![CDATA[#FFFFFFFF]]></p:property><p:property name="textAlign"><![CDATA[1,1]]></p:property></p:metadata>
  36 +
  37 + <defs>
  38 + <rect width="210" height="550" rx="7" ry="7" x="0" y="0" style="stroke-width: 0pt; fill: rgb(255, 255, 255); fill-opacity: 1; stroke: rgb(0, 0, 0); stroke-opacity: 1;" p:name="rrRect" id="rrRect21247050338773133" transform="translate(0)"/>
  39 + <filter height="1.2558399" y="-0.12792" width="1.06396" x="-0.03198" p:name="shadingFilter" id="shadingFilter21247050338773133">
  40 + <feGaussianBlur stdDeviation="1" in="SourceAlpha"/>
  41 + </filter>
  42 + </defs>
  43 + <use xlink:href="#rrRect21247050338773133" xmlns:xlink="http://www.w3.org/1999/xlink" transform="translate(2, 2)" p:filter="url(#shadingFilter21247050338773133)" style="opacity: 0.5; visibility: hidden;" p:heavy="true" p:name="bgCopy" id="bgCopy21247050338773133"/>
  44 + <use xlink:href="#rrRect21247050338773133" xmlns:xlink="http://www.w3.org/1999/xlink"/>
  45 + <foreignObject x="10" y="275" width="190" height="0" p:name="text" id="text21247050338773133" style="font-family: Arial; font-size: 12px; font-weight: normal; font-style: normal; text-decoration: none; fill: rgb(255, 255, 255); fill-opacity: 1; color: rgb(255, 255, 255); opacity: 1; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml"/></foreignObject><path id="text21247050338773_underline133" style="fill: none; stroke-width: 1px; visibility: hidden;"/>
  46 + </g><g xmlns="http://www.w3.org/2000/svg" p:type="Shape" xmlns:p="http://www.evolus.vn/Namespace/Pencil" p:def="Evolus.Common:RoundedRect" transform="matrix(1, 0, 0, 1, 15, 8)"><p:metadata><p:property name="box"><![CDATA[995,72]]></p:property><p:property name="withBlur"><![CDATA[false]]></p:property><p:property name="radius"><![CDATA[7,0]]></p:property><p:property name="textPadding"><![CDATA[0,10]]></p:property><p:property name="fillColor"><![CDATA[#FFFFFFFF]]></p:property><p:property name="strokeColor"><![CDATA[#000000FF]]></p:property><p:property name="strokeStyle"><![CDATA[0|]]></p:property><p:property name="textContent"><![CDATA[]]></p:property><p:property name="textFont"><![CDATA[Arial|normal|normal|12px|none]]></p:property><p:property name="textColor"><![CDATA[#FFFFFFFF]]></p:property><p:property name="textAlign"><![CDATA[1,1]]></p:property></p:metadata>
  47 +
  48 + <defs>
  49 + <rect width="995" height="72" rx="7" ry="7" x="0" y="0" style="stroke-width: 0pt; fill: rgb(255, 255, 255); fill-opacity: 1; stroke: rgb(0, 0, 0); stroke-opacity: 1;" p:name="rrRect" id="rrRect21247050338773112" transform="translate(0)"/>
  50 + <filter height="1.2558399" y="-0.12792" width="1.06396" x="-0.03198" p:name="shadingFilter" id="shadingFilter21247050338773112">
  51 + <feGaussianBlur stdDeviation="1" in="SourceAlpha"/>
  52 + </filter>
  53 + </defs>
  54 + <use xlink:href="#rrRect21247050338773112" xmlns:xlink="http://www.w3.org/1999/xlink" transform="translate(2, 2)" p:filter="url(#shadingFilter21247050338773112)" style="opacity: 0.5; visibility: hidden;" p:heavy="true" p:name="bgCopy" id="bgCopy21247050338773112"/>
  55 + <use xlink:href="#rrRect21247050338773112" xmlns:xlink="http://www.w3.org/1999/xlink"/>
  56 + <foreignObject x="10" y="36" width="975" height="0" p:name="text" id="text21247050338773112" style="font-family: Arial; font-size: 12px; font-weight: normal; font-style: normal; text-decoration: none; fill: rgb(255, 255, 255); fill-opacity: 1; color: rgb(255, 255, 255); opacity: 1; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml"/></foreignObject><path id="text21247050338773112_underline" style="fill: none; stroke-width: 1px; visibility: hidden;"/><path id="text21247050338773_underline112" style="fill: none; stroke-width: 1px; visibility: hidden;"/>
  57 + </g><g xmlns="http://www.w3.org/2000/svg" p:type="Shape" xmlns:p="http://www.evolus.vn/Namespace/Pencil" p:def="Evolus.Common:RoundedRect" transform="matrix(1, 0, 0, 1, 15, 655)"><p:metadata><p:property name="box"><![CDATA[995,72]]></p:property><p:property name="withBlur"><![CDATA[false]]></p:property><p:property name="radius"><![CDATA[7,0]]></p:property><p:property name="textPadding"><![CDATA[0,10]]></p:property><p:property name="fillColor"><![CDATA[#FFFFFFFF]]></p:property><p:property name="strokeColor"><![CDATA[#000000FF]]></p:property><p:property name="strokeStyle"><![CDATA[0|]]></p:property><p:property name="textContent"><![CDATA[]]></p:property><p:property name="textFont"><![CDATA[Arial|normal|normal|12px|none]]></p:property><p:property name="textColor"><![CDATA[#FFFFFFFF]]></p:property><p:property name="textAlign"><![CDATA[1,1]]></p:property></p:metadata>
  58 +
  59 + <defs>
  60 + <rect width="995" height="72" rx="7" ry="7" x="0" y="0" style="stroke-width: 0pt; fill: rgb(255, 255, 255); fill-opacity: 1; stroke: rgb(0, 0, 0); stroke-opacity: 1;" p:name="rrRect" id="rrRect2124705033877311249" transform="translate(0)"/>
  61 + <filter height="1.2558399" y="-0.12792" width="1.06396" x="-0.03198" p:name="shadingFilter" id="shadingFilter2124705033877311249">
  62 + <feGaussianBlur stdDeviation="1" in="SourceAlpha"/>
  63 + </filter>
  64 + </defs>
  65 + <use xlink:href="#rrRect2124705033877311249" xmlns:xlink="http://www.w3.org/1999/xlink" transform="translate(2, 2)" p:filter="url(#shadingFilter2124705033877311249)" style="opacity: 0.5; visibility: hidden;" p:heavy="true" p:name="bgCopy" id="bgCopy2124705033877311249"/>
  66 + <use xlink:href="#rrRect2124705033877311249" xmlns:xlink="http://www.w3.org/1999/xlink"/>
  67 + <foreignObject x="10" y="36" width="975" height="0" p:name="text" id="text2124705033877311249" style="font-family: Arial; font-size: 12px; font-weight: normal; font-style: normal; text-decoration: none; fill: rgb(255, 255, 255); fill-opacity: 1; color: rgb(255, 255, 255); opacity: 1; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml"/></foreignObject><path id="text21247050338773112_underline49" style="fill: none; stroke-width: 1px; visibility: hidden;"/><path id="text21247050338773_underline11249" style="fill: none; stroke-width: 1px; visibility: hidden;"/>
  68 + </g></Content></Page></Pages></Document>
0 69 \ No newline at end of file
... ...
ktwebservice/KTDownloadManager.inc.php
... ... @@ -60,10 +60,8 @@ class KTDownloadManager
60 60 $this->age = $config->get('webservice/downloadExpiry',5);
61 61  
62 62 $protocol = $config->get('KnowledgeTree/sslEnabled')?'https':'http';
63   - $server = KTUtil::getServerName(TRUE);
64   - $url = $config->get('webservice/downloadUrl');
65 63  
66   - $this->download_url = $protocol . '://' . $server . $url;
  64 + $this->download_url = $protocol . '://' . $_SERVER['HTTP_HOST'] . $config->get('webservice/downloadUrl');
67 65 $this->random=$config->get('webservice/randomKeyText','jhsdf8q1jkjpoiudfs7sd3ds1');
68 66 }
69 67  
... ...
ktwebservice/KTUploadManager.inc.php
... ... @@ -110,7 +110,6 @@ class KTUploadManager
110 110 return ($tempdir == $this->temp_dir);
111 111 */
112 112 }
113   -
114 113 function store_base64_file($base64, $prefix= 'sa_')
115 114 {
116 115 $tempfilename = $this->get_temp_filename($prefix);
... ... @@ -134,36 +133,6 @@ class KTUploadManager
134 133  
135 134 return $tempfilename;
136 135 }
137   -
138   - /**
139   - *
140   - * @param string $content file content NOT base64 encoded (may be string, may be binary)
141   - * @param string $prefix [optional]
142   - * @return $tempfilename the name of the temporary file created
143   - */
144   - function store_file($content, $prefix= 'sa_')
145   - {
146   - $tempfilename = $this->get_temp_filename($prefix);
147   - if (!is_writable($tempfilename))
148   - {
149   - return new PEAR_Error("Cannot write to file: $tempfilename");
150   - }
151   -
152   - if (!$this->is_valid_temporary_file($tempfilename))
153   - {
154   - return new PEAR_Error("Invalid temporary file: $tempfilename. There is a problem with the temporary storage path: $this->temp_dir.");
155   - }
156   -
157   - $fp=fopen($tempfilename, 'wb');
158   - if ($fp === false)
159   - {
160   - return new PEAR_Error("Cannot write content to temporary file: $tempfilename.");
161   - }
162   - fwrite($fp, $content);
163   - fclose($fp);
164   -
165   - return $tempfilename;
166   - }
167 136  
168 137 /**
169 138 * This tells the manager to manage a file that has been uploaded.
... ...
ktwebservice/download.php
... ... @@ -77,7 +77,7 @@ $response = $download_manager-&gt;download($document_id, $hash, null, $apptype);
77 77 if (PEAR::isError($response))
78 78 {
79 79 $msg = urlencode($response->getMessage());
80   - print "status_code=4&msg=$msg";
  80 + print "status_code=4&msg=$msg:".$_GET["u"].":".$_GET["d"].":".$_GET["code"].":".$_GET["apptype"].":";
81 81 exit;
82 82 }
83 83  
... ...
ktwebservice/upload.php
... ... @@ -117,6 +117,7 @@ foreach($_FILES as $key =&gt;$file)
117 117 $tempfile=$file['tmp_name'];
118 118  
119 119 $error=$file['error'];
  120 + $extra = $filename.'-'.$tempfile.'-'.$error;
120 121 if ($error == UPLOAD_ERR_OK)
121 122 {
122 123 $result = $upload_manager->uploaded($filename, $tempfile, $action);
... ... @@ -145,7 +146,7 @@ if ($failed)
145 146 }
146 147 else
147 148 {
148   - respond(0, '', $added);
  149 + respond(0, 'It worked'.$extra, $added);
149 150 }
150 151  
151 152 function respond($code, $msg, $uploads=array())
... ...
webservice/clienttools/ajaxhandler.php
... ... @@ -7,12 +7,19 @@ class ajaxHandler{
7 7 public $request=NULL;
8 8 public $kt=NULL;
9 9 public $authenticator=NULL;
  10 + public $noAuthRequireList=array();
10 11  
11   - public function __construct(&$ret=NULL,&$kt){
  12 + public function __construct(&$ret=NULL,&$kt,$noAuthRequests=''){
12 13 // set a local copy of the json request wrapper
  14 + $noAuthRequests=is_array($noAuthRequests)?$noAuthRequests:split(',',(string)$noAuthRequests);
  15 + $this->registerNoAuthRequest($noAuthRequests);
13 16 $this->req=new jsonWrapper(isset($_GET['request'])?$_GET['request']:(isset($_POST['request'])?$_POST['request']:''));
14   - $this->auth=$this->req->jsonArray['auth'];
15   - $this->request=$this->req->jsonArray['request'];
  17 + $this->auth=$this->structArray('user,pass,passhash,appType,session,token,version',$this->req->jsonArray['auth']);
  18 + $this->request=$this->structArray('service,function,parameters',$this->req->jsonArray['request']);
  19 +
  20 + $add_params=array_merge($_GET,$_POST);
  21 + unset($add_params['request'],$add_params['datasource']);
  22 + $this->request['parameters']=array_merge($this->request['parameters'],$add_params);
16 23  
17 24  
18 25 // set the response object
... ... @@ -22,6 +29,7 @@ class ajaxHandler{
22 29 $this->ret=new jsonResponseObject();
23 30 }
24 31 $this->ret->setRequest($this->req->jsonArray);
  32 + $this->ret->setTitle($this->request['service'].'::'.$this->request['function']);
25 33  
26 34 if(get_class($kt)=='KTAPI'){
27 35 $this->kt=&$kt;
... ... @@ -41,21 +49,32 @@ class ajaxHandler{
41 49  
42 50 if(!$this->verifySession()){
43 51 $this->doLogin();
44   - if(!$this->isAuthenticated())return $this->render();
  52 + $isAuthRequired=$this->isNoAuthRequiredRequest();
  53 + $isAuthenticated=$this->isAuthenticated();
  54 + if(!$isAuthRequired && !$isAuthenticated)return $this->render();
45 55 }
46 56  
47 57 $this->dispatch();
48 58  
49 59 return $this->render();
50 60 }
  61 +
  62 + private function structArray($structString=NULL,$arr=NULL){
  63 + $struct=array_flip(split(',',(string)$structString));
  64 + return array_merge($struct,is_array($arr)?$arr:array());
  65 + }
51 66  
52 67 public function dispatch(){
53 68 $request=$this->request;
54   - $this->loadService($request['service']);
55   - $service=new $request['service']($this->ret,$this->kt,$this->request,$this->auth);
56   - $this->ret->setTitle($request['service'].'::'.$request['function']);
  69 + if($request['auth']){
  70 + $service=$this->authenticator;
  71 + }else{
  72 + $this->loadService($request['service']);
  73 + $service=new $request['service']($this->ret,$this->kt,$this->request,$this->auth);
  74 + }
  75 + $this->ret->setdebug('dispatch_request','The service class loaded');
57 76 if(method_exists($service,$request['function'])){
58   - //$this->ret->setDebug('got here');
  77 + $this->ret->setdebug('dispatch_execution','The service method was found. Executing');
59 78 $service->$request['function']($request['parameters']);
60 79 }else{
61 80 $this->ret->addError("Service {$request['service']} does not contain the method: {$request['function']}");
... ... @@ -97,7 +116,7 @@ class ajaxHandler{
97 116 }
98 117  
99 118 protected function isAuthenticated(){
100   - return true;
  119 + return $this->authenticator->pickup_session();
101 120 }
102 121  
103 122 protected function doLogin(){
... ... @@ -113,6 +132,26 @@ class ajaxHandler{
113 132 echo $this->ret->getJson();
114 133 return true;
115 134 }
  135 +
  136 + public function registerNoAuthRequest($requestString=''){
  137 + if($requestString){
  138 + if(is_array($requestString)){
  139 + foreach ($requestString as $rString){
  140 + $rString=strtolower((string)$rString);
  141 + $this->noAuthRequireList[$rString]=$rString;
  142 + }
  143 + }else{
  144 + $requestString=strtolower((string)$requestString);
  145 + $this->noAuthRequireList[$requestString]=(string)$requestString;
  146 + }
  147 + }
  148 + }
  149 +
  150 + public function isNoAuthRequiredRequest(){
  151 + $req=$this->request;
  152 + $reqString=strtolower("{$req['service']}.{$req['function']}");
  153 + return in_array($reqString,$this->noAuthRequireList);
  154 + }
116 155  
117 156 }
118 157 ?>
119 158 \ No newline at end of file
... ...
webservice/clienttools/client_service.php
... ... @@ -41,6 +41,17 @@ class client_service{
41 41 return $var;
42 42 }
43 43  
  44 + protected function checkPearError($obj,$errMsg,$debug=NULL,$response=NULL){
  45 + if (PEAR::isError($obj)){
  46 + if($response===NULL)$response=array('status_code' => 1);
  47 + $this->addError($errMsg);
  48 + if((isset($debug) || $debug==NULL) && $debug!=='')$this->addDebug('',$debug!==NULL?$debug:$obj);
  49 + $this->setResponse($response);
  50 + return false;
  51 + }
  52 + return true;
  53 + }
  54 +
44 55 }
45 56  
46 57 ?>
47 58 \ No newline at end of file
... ...
webservice/clienttools/comms.php
... ... @@ -38,12 +38,23 @@ $old_error_handler=set_error_handler(&#39;error_handler&#39;,E_ERROR);
38 38 //Interpret the Json Object that was passed
39 39 include_once('jsonWrapper.php');
40 40 include_once('ajaxhandler.php');
  41 +include_once('serviceHelper.php');
41 42 include_once('client_service.php');
42 43  
43 44 //Instantiate base classes
44 45 $KT = new KTAPI();
45 46 $RET=new jsonResponseObject();
46   -$handler=new ajaxHandler($RET,$KT);
  47 +if($_GET['datasource'])$RET->isDataSource=true;
  48 +
  49 +$noAuthRequests=array(
  50 + 'auth.ping',
  51 + 'auth.japiLogin',
  52 + 'kt.get_all_client_policies',
  53 + 'kt.get_languages',
  54 + 'kt.switchlang'
  55 +);
  56 +
  57 +$handler=new ajaxHandler($RET,$KT,$noAuthRequests);
47 58  
48 59  
49 60  
... ...
webservice/clienttools/jsonWrapper.php
... ... @@ -12,6 +12,7 @@ class jsonResponseObject{
12 12 protected $request=array();
13 13 protected $debug=array();
14 14 public $additional=array();
  15 + public $isDataSource=false;
15 16  
16 17 public $response=array(
17 18 'requestName' =>'',
... ... @@ -60,7 +61,7 @@ class jsonResponseObject{
60 61  
61 62 public function getJson(){
62 63 $response=array_merge(array(
63   - 'title' =>$this->title,
  64 + 'requestName' =>$this->title,
64 65 'errors' =>array(
65 66 'hadErrors' =>(count($this->errors)>0?1:0),
66 67 'errors' =>$this->errors
... ... @@ -71,7 +72,11 @@ class jsonResponseObject{
71 72 'debug' =>$this->debug,
72 73 ),$this->additional);
73 74  
74   - $response=json_encode($response);
  75 + if($this->isDataSource){
  76 + $response=json_encode($response['data']);
  77 + }else{
  78 + $response=json_encode($response);
  79 + }
75 80 return $response;
76 81 }
77 82 }
... ...
webservice/clienttools/serviceHelper.php 0 → 100644
  1 +<?php
  2 +class serviceHelper{
  3 + public function __construct(){
  4 + throw new Exception('ServiceHelper is only to be used statically');
  5 + }
  6 +
  7 + function bool2str($bool){
  8 + //TODO: Test this sometime.. a lot shorter - doesn't cater for string though.. but if string then result already correct
  9 + //return ((bool)$bool)?'true':false;
  10 +
  11 + if (is_bool($bool))
  12 + {
  13 + return $bool ? 'true' : 'false';
  14 + }
  15 + if (is_numeric($bool))
  16 + {
  17 + return ($bool+0) ? 'true' : 'false';
  18 + }
  19 + // assume str
  20 + return (strtolower($bool) == 'true') ? 'true' : 'false';
  21 + }
  22 +
  23 + /**
  24 + * Return human readable sizes
  25 + *
  26 + * @param integer $size The size you want to convert to human readable
  27 + * @return string
  28 + */
  29 + function fsize_desc($size){
  30 + $i=0;
  31 + $iec = array("B", "Kb", "Mb", "Gb", "Tb");
  32 + while (($size/1024)>1) {
  33 + $size=$size/1024;
  34 + $i++;
  35 + }
  36 + return substr($size,0,strpos($size,'.')+3).$iec[$i];
  37 + }
  38 +
  39 +
  40 + /**
  41 + * Display byte sizes in human readable representations
  42 + *
  43 + * @param integer $size Size to represent
  44 + * @param string $max Maximum representational unit (eg B,KB,MB)
  45 + * @param string $system Selecting the system of representation (si,bi&c1 defined)
  46 + * @param string $retstring Format for the return string.
  47 + * @return String
  48 + */
  49 + function size_readable($size, $max = null, $system = 'c1', $retstring = '%01.1f %s'){
  50 + // Pick units
  51 + $systems['si']['prefix'] = array('B', 'K', 'MB', 'GB', 'TB', 'PB');
  52 + $systems['si']['size'] = 1000;
  53 + $systems['bi']['prefix'] = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB');
  54 + $systems['bi']['size'] = 1024;
  55 + $systems['c1']['prefix'] = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
  56 + $systems['c1']['size'] = 1024;
  57 + $sys = isset($systems[$system]) ? $systems[$system] : $systems['si'];
  58 +
  59 + // Max unit to display
  60 + $depth = count($sys['prefix']) - 1;
  61 + if ($max && false !== $d = array_search($max, $sys['prefix'])) {
  62 + $depth = $d;
  63 + }
  64 +
  65 + // Loop
  66 + $i = 0;
  67 + while ($size >= $sys['size'] && $i < $depth) {
  68 + $size /= $sys['size'];
  69 + $i++;
  70 + }
  71 +
  72 + return sprintf(($sys['prefix'][$i]=='B'?'%01d %s':$retstring), $size, $sys['prefix'][$i]);
  73 + }
  74 +}
  75 +?>
0 76 \ No newline at end of file
... ...
webservice/clienttools/services/3.6.1/auth.php
... ... @@ -23,7 +23,9 @@ class auth extends client_service {
23 23 require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php');
24 24  
25 25 if (!BaobabKeyUtil::checkIfLicensed(true)) {
26   - return array('authenticated'=> false, 'message'=> 'license_expired');
  26 + $this->setResponse(array('authenticated'=> false, 'message'=> 'license_expired'));
  27 + $this->addError('Licence Expired');
  28 + return false;
27 29 }
28 30 }
29 31  
... ... @@ -38,21 +40,34 @@ class auth extends client_service {
38 40 if(!PEAR::isError($session)){
39 41 $this->Response->setStatus('session_id',$session->get_session());
40 42 }else{
41   - $this->Response->setDebug('failed login',print_r($session,true));
42   - throw new Exception('Unknown Login Error');
  43 + $this->setResponse(array('authenticated'=> false, 'message'=> 'Invalid username and/or password.'));
  44 + $this->addDebug('failed login',print_r($session,true));
  45 + $this->addError('Unknown Login Error');
43 46 return false;
44 47 }
45 48 }else{
46   - throw new Exception('Incorrect Credentials');
  49 + $this->addError('Incorrect Credentials');
  50 + //throw new Exception('Incorrect Credentials');
47 51 return false;
48 52 }
49 53 }else{
50   - throw new Exception('Unrecognized User');
  54 + $this->addError('Incorrect Credentials');
  55 + //throw new Exception('Unrecognized User');
51 56 return false;
52 57 }
53 58 return true;
54 59 }
55 60  
  61 + public function japiLogin(){
  62 + global $default;
  63 + $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']);
  64 + $ret=array(
  65 + 'fullName' =>PEAR::isError($user)?'':$user->getName()
  66 + );
  67 + $this->setResponse($ret);
  68 + return true;
  69 + }
  70 +
56 71 public function pickup_session(){
57 72 $params=$this->AuthInfo;
58 73 $app_type=$params['appType'];
... ... @@ -67,6 +82,40 @@ class auth extends client_service {
67 82 $this->Response->setStatus('session_id',$session->get_session());
68 83 return true;
69 84 }
  85 +
  86 +
  87 + public function ping(){
  88 + global $default;
  89 + $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']);
  90 + $ret=array(
  91 + 'response' =>'pong',
  92 + 'loginLocation' => '/index.html',
  93 + 'currentversion' =>$default->systemVersion,
  94 + 'requiredversion' =>$default->systemVersion,
  95 + 'versionok' =>true,
  96 + 'fullName' =>PEAR::isError($user)?'':$user->getName()
  97 + );
  98 + $this->setResponse($ret);
  99 + return true;
  100 + }
  101 +
  102 + function logout($params){
  103 + $params=$this->AuthInfo;
  104 + $app_type=$params['appType'];
  105 + $session_id=$params['session'];
  106 + $ip=$_SERVER['REMOTE_ADDR'];
  107 +
  108 + $session = $this->KT->get_active_session($session_id, $ip, $app_type);
  109 +
  110 + if (PEAR::isError($session)){
  111 + return false;
  112 + }
  113 +
  114 + $session->logout();
  115 + $this->setResponse(array('logout'=>true));
  116 + return true;
  117 + }
  118 +
70 119 }
71 120  
72 121 ?>
73 122 \ No newline at end of file
... ...
webservice/clienttools/services/3.6.1/kt.php
1 1 <?php
2 2 class kt extends client_service {
  3 +
3 4  
  5 +
4 6 /**
5 7 * Get Supported (?) Languages
6 8 *
7 9 * returns array containing languages, count, & defaultlanguage
8 10 *
9 11 */
10   - function get_languages(){
  12 + function get_languages($passthru=false){
11 13 global $default;
12 14 $oReg =& KTi18nregistry::getSingleton();
13   - $aRegisteredLangs = $oReg->geti18nLanguages('knowledgeTree');
14   - $aLanguageNames = $oReg->getLanguages('knowledgeTree');
15   - $languages = array();
  15 + $aRegisteredLangs=$oReg->geti18nLanguages('knowledgeTree');
  16 + $aLanguageNames=$oReg->getLanguages('knowledgeTree');
  17 + $languages=array();
16 18  
17 19 if(!empty($aRegisteredLangs)){
18 20 foreach (array_keys($aRegisteredLangs) as $sLang){
19   - $languages[] = array(
20   - 'isoCode' => $sLang,
21   - 'language' => $aLanguageNames[$sLang]
  21 + $languages[]=array(
  22 + 'isoCode'=>$sLang,
  23 + 'language'=>$aLanguageNames[$sLang]
22 24 );
23 25 }
24 26 }
25   -
26   - $this->setResponse(array('languages' => $languages, 'count' => count($languages), 'defaultLanguage' => $default->defaultLanguage));
  27 + $response=array('languages'=>$languages, 'count'=>count($languages), 'defaultLanguage'=>$default->defaultLanguage);
  28 + if(is_bool($passthru))if($passthru)return $response;
  29 + $this->setResponse($response);
27 30 }
28 31  
29 32  
30 33 function get_rootfolder_detail($params){
31   - $params['folderId'] = '1';
  34 + $params['folderId']='1';
32 35 $this->get_folder_detail($params);
33 36 }
34 37  
35 38  
36 39 function get_folder_detail($params) {
37   - $kt = &$this->KT;
  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;
38 45  
39   - $folder = &$kt->get_folder_by_id($params['folderId']);
  46 + $folder=&$kt->get_folder_by_id($params['folderId']);
40 47 if (PEAR::isError($folder))
41 48 {
42 49 $this->setError("Could not get folder by Id: {$params['folderId']}");
43 50 $this->setDebug('FolderError',array('kt'=>$kt,'folder'=>$folder));
44   - return;
  51 + return false;
45 52 }
46 53  
47   - $detail = $folder->get_detail();
48   - if (PEAR::isError($detail))
49   - {
50   - $this->response= "detail error {$params['node']}";
  54 + $detail=$folder->get_detail();
  55 + if (PEAR::isError($detail)){
  56 + $this->setResponse("detail error {$params['node']}");
  57 + return false;
51 58 }
52 59  
53   - if(strtolower($detail['folder_name']) == 'root folder') {
54   - $detail['folder_name'] = 'KnowledgeTree';
  60 + if(strtolower($detail['folder_name'])=='root folder'){
  61 + $detail['folder_name']='KnowledgeTree';
55 62 }
56 63  
57 64 $qtip .= $this->xlate('Folder name').": {$detail['folder_name']}<br>";
58   - $class = 'folder';
  65 + $class='folder';
59 66  
60   - $permissions = $detail['permissions'];
61   - $perms = '';
62   - //default write permissions to false
63   - $canWrite = false;
  67 + $permissions=$detail['permissions'];
  68 + $perms='';
  69 + $canWrite=false;
64 70  
65   - //iterate through the permissions and convert to human-readable
66   - for ($j = 0; $j < strlen($permissions); $j++)
67   - {
68   - switch (strtoupper($permissions{$j}))
69   - {
  71 + for ($j=0; $j < strlen($permissions); $j++){
  72 + switch (strtoupper($permissions{$j})){
70 73 case 'W':
71   - $canWrite = true;
  74 + $canWrite=true;
72 75 $perms .= $this->xlate('write, ');
73 76 break;
74 77 case 'R':
... ... @@ -80,227 +83,195 @@ class kt extends client_service {
80 83 }
81 84 }
82 85  
83   - //now chop off trailing ', ' if any
84   - if (strlen($perms) > 2)
85   - {
86   - $perms = substr($perms, 0, strlen($perms)-2);
  86 + if (strlen($perms) > 2){
  87 + $perms=substr($perms, 0, strlen($perms)-2);
87 88 }
88 89  
89   - //permissions
90 90 $qtip .= $this->xlate('Permissions:') . " {$perms}<br>";
91   -
92   - //comment
93 91 $qtip .= $canWrite ? $this->xlate('You may add content to this folder') : $this->xlate('You may not add content to this folder');
94 92  
95   - $result[] = array
96   - (
97   - 'text' => $detail['folder_name'],
98   - 'id' => $params['control'] . $params['node'],
99   - 'filename' => $detail['folder_name'],
100   - 'cls' => 'folder',
101   - 'leaf' => false,
102   - 'document_type' => '',
103   - 'item_type' => 'F',
104   - 'permissions' => $permissions,
  93 + $result[]=array(
  94 + 'text'=>$detail['folder_name'],
  95 + 'id'=>'F_'. $params['folderId'],
  96 + 'filename'=>$detail['folder_name'],
  97 + 'cls'=>'folder',
  98 + 'leaf'=>false,
  99 + 'document_type'=>'',
  100 + 'item_type'=>'F',
  101 + 'permissions'=>$permissions,
105 102 'qtip'=> $qtip
106 103 );
107 104  
108 105 $this->setResponse($result);
  106 + return true;
109 107 }
110 108  
111 109  
112 110 function get_folder_contents($params){
113 111 $kt=&$this->KT;
114 112  
115   - $params['control'] = 'F_';
116   - $params['node'] = substr($params['node'], strlen($params['control']));
  113 + $params['control']='F_';
  114 + $params['node']=substr($params['node'], strlen($params['control']));
117 115  
118   - $folder = &$kt->get_folder_by_id($params['node']);
119   - if (PEAR::isError($folder)){
120   - $this->addError("[error 1] Folder Not Found: {$params['control']}{$params['node']}");
121   - return false;
122   - }
  116 + $folder=&$kt->get_folder_by_id($params['node']);
  117 + if(!$this->checkPearError($folder,"[error 1] Folder Not Found: {$params['control']}{$params['node']}",'',array()))return false;
123 118  
124   - $types = (isset($params['types']) ? $params['types'] : 'DF');
  119 + $types=(isset($params['types']) ? $params['types'] : 'DF');
  120 + $listing=$folder->get_listing(1, $types);
  121 + $result=$this->_processListing($listing, 'folderContents', $params);
125 122  
126   - $listing = $folder->get_listing(1, $types);
  123 + $this->setResponse($result);
  124 + return true;
  125 + }
127 126  
128   - $result = $this->_processListing($listing, 'folderContents', $params);
129 127  
130   - $this->setResponse($result);
  128 + /**
  129 + * Returns the contents of a folder formatted for a grid view.
  130 + *
  131 + * @param array $arr
  132 + * @return array
  133 + */
  134 + function get_folder_contents_for_grid($arr)
  135 + {
  136 + $kt=&$this->KT;
  137 +
  138 + $arr['control']='F_';
  139 + $arr['node']=substr($arr['node'], strlen($arr['control']));
  140 +
  141 + $folder=&$kt->get_folder_by_id($arr['node']);
  142 + if (PEAR::isError($folder)){
  143 + $this->addError('Folder Not found');
  144 + return false;
  145 + }
  146 +
  147 + $types=(isset($arr['types']) ? $arr['types'] : 'DF');
  148 +
  149 + $listing=$folder->get_listing(1, $types);
  150 +
  151 + $result=$this->_processListing($listing, 'grid', $arr);
  152 +
  153 + $this->setResponse(array('totalCount'=>count($listing), 'items'=>$result));
  154 +
  155 + return true;
131 156 }
132 157  
133   -
  158 +
  159 +
134 160 private function _processListing($listing, $type, $arr){
135   - $result = array();
136   - $methodToIncludeItem = '_processItemInclusion_'.$type;
137   -
138   - foreach ($listing as $item)
139   - {
140   - $filename = $item['filename'];
141   - $itemType = $item['item_type'];
142   -
143   - $includeMe = true;
144   -
145   - //build up tooltip
146   - $qtip = '';
147   -
148   - //default write permissions to false
149   - $canWrite = false;
150   - //default immutable to false
151   - $immutable = false;
152   -
153   - //first do permissions since they are applicable to both folders and docs
154   - $permissions = $item['permissions'];
155   - $perms = '';
156   -
157   - //iterate through the permissions and convert to human-readable
158   - for ($j = 0; $j < strlen($permissions); $j++)
159   - {
160   - switch (strtoupper($permissions{$j}))
161   - {
  161 + $result=array();
  162 + $methodToIncludeItem='_processItemInclusion_'.$type;
  163 +
  164 + foreach($listing as $item){
  165 + /* Trying to fix folder sizes */
  166 + if($item['filesize']<=0){
  167 + $item['filesize']='';
  168 + }else{
  169 + $item['filesize']=serviceHelper::size_readable($item['filesize']);
  170 + }
  171 +
  172 + $filename=$item['filename'];
  173 + $itemType=$item['item_type'];
  174 +
  175 + $includeMe=true;
  176 + $qtip='';
  177 + $canWrite=false;
  178 + $immutable=false;
  179 + $permissions=$item['permissions'];
  180 + $perms='';
  181 +
  182 + for ($j=0; $j < strlen($permissions); $j++){
  183 + switch (strtoupper($permissions{$j})){
162 184 case 'W':
163   - $canWrite = true;
  185 + $canWrite=true;
164 186 $perms .= $this->xlate('write, ');
165   - break;
  187 + break;
166 188 case 'R':
167 189 $perms .= $this->xlate('read, ');
168   - break;
  190 + break;
169 191 case 'A':
170 192 $perms .= $this->xlate('add folder, ');
171   - break;
172   - // default:
173   - // $perms .= strtoupper($permissions{$j});
174   - // break;
  193 + break;
175 194 }
176 195 }
177 196  
178   - //now chop off trailing ', ' if any
179   - if (strlen($perms) > 2)
180   - {
181   - $perms = substr($perms, 0, strlen($perms)-2);
  197 + if(strlen($perms) > 2){
  198 + $perms=substr($perms, 0, strlen($perms)-2);
182 199 }
183 200  
184   - //folders
185   - if ($itemType == 'F')
186   - {
  201 + if($itemType=='F'){
187 202 $qtip .= $this->xlate('Folder name').": {$filename}<br>";
188   - $class = 'folder';
189   -
190   - //permissions
  203 + $class='folder';
191 204 $qtip .= $this->xlate('Permissions:') . " {$perms}<br>";
192   -
193   - //comment
194 205 $qtip .= $canWrite ? $this->xlate('You may add content to this folder') : $this->xlate('You may not add content to this folder');
195 206 }
196 207  
197 208 //documents
198   - else
199   - {
200   - $qtip = '';
201   -
202   - //get file extension so can determine mimetype
203   - $extpos = strrpos($filename, '.') ;
204   -
205   - if ($extpos === false)
206   - {
207   - $class = 'file-unknown';
  209 + else{
  210 + $qtip='';
  211 + $extpos=strrpos($filename, '.') ;
  212 +
  213 + if($extpos === false){
  214 + $class='file-unknown';
  215 + }else{
  216 + $ext=substr($filename, $extpos); // Get Extension including the dot
  217 + $class='file-' . substr($filename, $extpos +1); // Get Extension without the dot
208 218 }
209   - else
210   - {
211   - $ext = substr($filename, $extpos); // Get Extension including the dot
212   - $class = 'file-' . substr($filename, $extpos +1); // Get Extension without the dot
213   - }
214   -
215   - // Convert list to array
216   - $extensions = explode(',', $arr['extensions']);
217   -
218   - //don't include results which don't have the correct file extensions
219   - if(!in_array(strtolower($ext), $extensions))
220   - {
221   - $includeMe = false;
222   - }
223   - else
224   - {
225   - //filename
  219 +
  220 + $extensions=explode(',', $arr['extensions']);
  221 + if(!in_array(strtolower($ext), $extensions)){
  222 + $includeMe=false;
  223 + }else{
226 224 $qtip .= $this->xlate('Filename') . ": {$filename}<br>";
227   -
228   - //size
229   - $qtip .= $this->xlate('File Size') . ": " . fsize_desc($item['filesize']) . "<br>";
230   -
231   - //last modified
  225 + $qtip .= $this->xlate('File Size') . ": " . serviceHelper::fsize_desc($item['filesize']) . "<br>";
232 226 $qtip .= $this->xlate('Modified') . ": {$item['modified_date']}<br>";
233   -
234   - //owner
235 227 $qtip .= $this->xlate('Owner') . ": {$item['created_by']}<br>";
236   -
237   - //version
238 228 $qtip .= $this->xlate('Version') . ": {$item['version']}<br>";
239   -
240   - //immutability
241   - if (bool2str(strtolower($item['is_immutable'])) == 'true')
242   - {
243   - $canWrite = false;
244   - $immutable = true;
  229 + if (serviceHelper::bool2str(strtolower($item['is_immutable']))=='true'){
  230 + $canWrite=false;
  231 + $immutable=true;
245 232 }
246   -
247   - //status, i.e. checked out or not, or immutable
248   - if ($immutable)
249   - {
  233 +
  234 + if($immutable){
250 235 $qtip .= $this->xlate('Status: Immutable') . '<br>';
251   - }
252   - else if (strtolower($item['checked_out_by']) != 'n/a' && ($item['checked_out_by'] != ''))
253   - {
  236 + }else if (strtolower($item['checked_out_by']) != 'n/a' && ($item['checked_out_by'] != '')){
254 237 $qtip .= $this->xlate('Status: Checked out by') . " {$item['checked_out_by']}<br>";
255   - }
256   - else
257   - {
  238 + }else{
258 239 $qtip .= $this->xlate('Status: Available') . '<br>';
259 240 }
260   -
261   - //permissions
262 241 $qtip .= $this->xlate('Permissions:') . " {$perms}<br>";
263 242  
264   - //immutable
265   - if($immutable)
266   - {
  243 + if($immutable){
267 244 $qtip .= $this->xlate('This document is not editable');
268   - }
269   - else if ($canWrite)
270   - {
  245 + }else if ($canWrite){
271 246 $qtip .= $this->xlate('You may edit this document');
272   - }
273   - else
274   - {
  247 + }else{
275 248 $qtip .= $this->xlate('This document is not editable');
276 249 }
277 250 }
278 251 }//end of if for files
279   - if($includeMe)
280   - {
281   - $result[] = $this->$methodToIncludeItem($item, $class, $qtip);
  252 + if($includeMe){
  253 + $result[]=$this->$methodToIncludeItem($item, $class, $qtip);
282 254 }
283 255 }
284   -
285 256 return $result;
286 257 }
287 258  
288 259  
289 260  
290 261  
291   - private function _processItemInclusion_folderContents($item, $class, $qtip)
292   - {
  262 + private function _processItemInclusion_folderContents($item, $class, $qtip){
293 263 return array (
294   - 'text' => htmlspecialchars($item['title']),
295   - 'originaltext' => $item['title'],
296   - 'id' => ($item['item_type'] == 'F' ? $item['item_type']."_" : "").$item['id'],
297   - 'filename' => $item['filename'],
298   - 'cls' => $class,
299   - 'leaf' => ($item['item_type'] == 'D'),
300   - 'document_type' => $item['document_type'],
301   - 'item_type' => $item['item_type'],
302   - 'permissions' => $item['permissions'],
303   - 'content_id' => $item['content_id'],
  264 + 'text'=>htmlspecialchars($item['title']),
  265 + 'originaltext'=>$item['title'],
  266 + 'id'=>($item['item_type']=='F' ? $item['item_type']."_" : "").$item['id'],
  267 + 'filename'=>$item['filename'],
  268 + 'cls'=>$class,
  269 + 'leaf'=>($item['item_type']=='D'),
  270 + 'document_type'=>$item['document_type'],
  271 + 'item_type'=>$item['item_type'],
  272 + 'permissions'=>$item['permissions'],
  273 + 'content_id'=>$item['content_id'],
  274 + 'checked_out_by'=>$item['checked_out_by'],
304 275 'qtip'=> $qtip
305 276 );
306 277 }
... ... @@ -309,128 +280,155 @@ class kt extends client_service {
309 280 private function _processItemInclusion_search($item, $class, $qtip)
310 281 {
311 282 return array (
312   - 'text' => htmlspecialchars($item['title']),
313   - 'originaltext' => $item['title'],
314   - 'id' => $item['document_id'],
315   - 'filename' => $item['filename'],
316   - 'cls' => $class,
317   - 'leaf' => true,
318   - 'document_type' => $item['document_type'],
319   - 'item_type' => 'D',
320   - 'permissions' => $item['permissions'],
321   - 'content_id' => $item['content_id'],
322   - 'relevance' => $item['relevance'],
  283 + 'text'=>htmlspecialchars($item['title']),
  284 + 'originaltext'=>$item['title'],
  285 + 'id'=>$item['document_id'],
  286 + 'filename'=>$item['filename'],
  287 + 'cls'=>$class,
  288 + 'leaf'=>true,
  289 + 'document_type'=>$item['document_type'],
  290 + 'item_type'=>'D',
  291 + 'permissions'=>$item['permissions'],
  292 + 'content_id'=>$item['content_id'],
  293 + 'relevance'=>$item['relevance'],
323 294 'qtip'=> $qtip
324 295 );
325 296 }
326 297  
  298 + private function _processItemInclusion_grid($item, $class, $qtip)
  299 + {
  300 + //var_dump($item);
  301 +
  302 + if ($item['filesize']=='n/a') {
  303 + $item['filesize']=-1;
  304 + }
  305 +
  306 + return array (
  307 + 'text'=>htmlspecialchars($item['title']),
  308 + 'originaltext'=>$item['title'],
  309 + 'id'=>$item['id'],
  310 + 'filename'=>$item['filename'],
  311 + 'cls'=>$class,
  312 + 'owner'=>$item['created_by'],
  313 + 'document_type'=>$item['document_type'],
  314 + 'item_type'=>$item['item_type'],
  315 + 'permissions'=>$item['permissions'],
  316 + 'content_id'=>$item['content_id'],
  317 + 'filesize'=>$item['filesize'],
  318 + 'modified'=>$item['modified_date'],
  319 + 'checked_out_by'=>$item['checked_out_by']
  320 + );
  321 + }
  322 +
327 323  
328   -
329 324 public function get_metadata($params) {
  325 + $kt=&$this->KT;
330 326  
331   - $kt = &$this->KT;
  327 + if (substr($params['document_id'], 0, 2)=='D_') {
  328 + $params['document_id']=substr($params['document_id'], 2);
  329 + }
332 330  
333   - $document_id = (int)$params['document_id'];
  331 + $document_id=(int)$params['document_id'];
334 332 if($document_id > 0) {
335   - $document = $kt->get_document_by_id($params['document_id']);
336   - $detail = $document->get_metadata();
337   - $document_detail = $document->get_detail();
338   - $title = $document_detail['title'];
339   - $document_type = $document_detail['document_type'];
  333 + $document=$kt->get_document_by_id($params['document_id']);
  334 + $detail=$document->get_metadata();
  335 + $document_detail=$document->get_detail();
  336 + $title=$document_detail['title'];
  337 + $document_type=$document_detail['document_type'];
340 338  
341   - } else {
  339 + }else{
342 340 if(isset($params['document_type'])) {
343   - $document_type = $params['document_type'];
344   - } else {
345   - $document_type = 'Default';
  341 + $document_type=$params['document_type'];
  342 + }else{
  343 + $document_type='Default';
346 344 }
347   - $detail = $kt->get_document_type_metadata($document_type);
348   - $title = "";
  345 + $detail=$kt->get_document_type_metadata($document_type);
  346 + $title="";
349 347 }
350 348  
351   - $result = array();
352   - $items = array();
353   - $index = 0;
354   - $items[] = array("name" => "__title", "index" => 0, "value" => $title, "control_type" => "string");
  349 + $result=array();
  350 + $items=array();
  351 + $index=0;
  352 + $items[]=array("name"=>"__title", "index"=>0, "value"=>$title, "control_type"=>"string");
355 353  
356 354  
357 355 // Commented out for timebeing - will be used by 'Save in Format'
358 356  
359 357 if (isset($params['extensions'])) {
360 358  
361   - $fileParts = pathinfo($document_detail['filename']);
  359 + $fileParts=pathinfo($document_detail['filename']);
362 360  
363   - $items[] = array("name" => "__document_extension", "index" => 0, "value" => strtolower($fileParts['extension']), "control_type" => "lookup", "selection" => explode(',', str_replace('.', '', $params['extensions'])));
  361 + $items[]=array("name"=>"__document_extension", "index"=>0, "value"=>strtolower($fileParts['extension']), "control_type"=>"lookup", "selection"=>explode(',', str_replace('.', '', $params['extensions'])));
364 362 }
365 363  
366   - $document_types = $this->get_documenttypes($params);
367   - $json_document_types = array();
  364 + $document_types=$this->get_documenttypes($params);
  365 + $json_document_types=array();
368 366 foreach($document_types['items'] as $val) {
369   - $json_document_types[] = $val['name'];
  367 + $json_document_types[]=$val['name'];
370 368 }
371   - $items[] = array("name" => "__document_type", "index" => 0, "value" => $document_type, "control_type" => "lookup", "selection" => $json_document_types);
  369 + $items[]=array("name"=>"__document_type", "index"=>0, "value"=>$document_type, "control_type"=>"lookup", "selection"=>$json_document_types);
372 370  
373 371  
374 372 for($i=0;$i<count($detail);$i++) {
375 373  
376 374 for($j=0;$j<count($detail[$i]['fields']);$j++)
377 375 {
378   - $items[] = array(
379   - 'fieldset' => $detail[$i]['fieldset'],
380   - 'name' => $detail[$i]['fields'][$j]['name'],
  376 + $items[]=array(
  377 + 'fieldset'=>$detail[$i]['fieldset'],
  378 + 'name'=>$detail[$i]['fields'][$j]['name'],
381 379  
382 380 // Change for value. If blank value is set to 1, change value to ''
383 381 // Overcomes issue of n/a
384   - 'value' => ($document_id > 0 ? ($detail[$i]['fields'][$j]['blankvalue'] == '1' ? '' : $detail[$i]['fields'][$j]['value']) : ''),
385   -
386   - 'description' => $detail[$i]['fields'][$j]['description'],
387   - 'control_type' => $detail[$i]['fields'][$j]['control_type'],
388   - 'selection' => $detail[$i]['fields'][$j]['selection'],
389   - 'required' => $detail[$i]['fields'][$j]['required'],
390   - 'blankvalue' => $detail[$i]['fields'][$j]['blankvalue'],
391   - 'index' => $index
  382 + 'value'=>($document_id > 0 ? ($detail[$i]['fields'][$j]['blankvalue']=='1' ? '' : $detail[$i]['fields'][$j]['value']) : ''),
  383 +
  384 + 'description'=>$detail[$i]['fields'][$j]['description'],
  385 + 'control_type'=>$detail[$i]['fields'][$j]['control_type'],
  386 + 'selection'=>$detail[$i]['fields'][$j]['selection'],
  387 + 'required'=>$detail[$i]['fields'][$j]['required'],
  388 + 'blankvalue'=>$detail[$i]['fields'][$j]['blankvalue'],
  389 + 'index'=>$index
392 390 );
393 391 $index++;
394 392 }
395 393 }
396 394  
397 395  
398   - $this->setResponse(array('id' => $title, 'items' => $items, 'count' => count($items)));
399   -
  396 + $this->setResponse(array('id'=>$title, 'items'=>$items, 'count'=>count($items)));
400 397  
  398 + return true;
401 399 }
402 400  
403 401  
404 402 public function get_documenttypes($params) {
405 403  
406   - $kt = &$this->KT;
  404 + $kt=&$this->KT;
407 405  
408   - $detail = $kt->get_documenttypes();
409   - $result = array();
410   - $items = array();
  406 + $detail=$kt->get_documenttypes();
  407 + $result=array();
  408 + $items=array();
411 409 for($i=0;$i<count($detail);$i++) {
412 410 if(strtolower(substr($detail[$i], -5)) != 'email')
413 411 {
414   - $items[] = array(
415   - 'name' => $detail[$i]
  412 + $items[]=array(
  413 + 'name'=>$detail[$i]
416 414 );
417 415 }
418 416 }
419   - $this->setResponse(array('items' => $items, 'count' => count($items)));
  417 + $this->setResponse(array('items'=>$items, 'count'=>count($items)));
420 418 }
421 419  
422 420 function update_document_type($params) {
423   - $kt = &$this->KT;
424   - $document_id = (int)$params['document_id'];
  421 + $kt=&$this->KT;
  422 + $document_id=(int)$params['document_id'];
425 423 if($document_id > 0) {
426   - $document = $kt->get_document_by_id($document_id);
  424 + $document=$kt->get_document_by_id($document_id);
427 425 $document->change_document_type($params['document_type']);
428   - $this->setResponse(array('status_code' => 0));
  426 + $this->setResponse(array('status_code'=>0));
429 427 return true;
430 428  
431 429 }else{
432 430 $this->addError("Invalid document Id : {$document_id}");
433   - $this->setResponse(array('status_code' => 1));
  431 + $this->setResponse(array('status_code'=>1));
434 432 return false;
435 433 }
436 434  
... ... @@ -447,35 +445,38 @@ class kt extends client_service {
447 445 $session_id=$params['session_id'];
448 446  
449 447  
450   - $document = &$kt->get_document_by_id($params['document_id']);
451   - $docname = $document->document->getFileName();
  448 + $document=&$kt->get_document_by_id($params['document_id']);
452 449 // $docname='test.txt';
453 450 if (PEAR::isError($document))
454 451 {
455   - $response['message'] = $document->getMessage();
456   - $this->debug("download_document - cannot get $document_id - " . $document->getMessage(), $session_id);
  452 + $response['message']=$document->getMessage();
  453 + $this->addDebug("download_document - cannot get $document_id - " . $document->getMessage(), $session_id);
457 454  
458   - $this->setResponse(new SOAP_Value('$this->response=',"{urn:$this->namespace}kt_response", $response));
  455 +// $this->setResponse(new SOAP_Value('$this->response=',"{urn:$this->namespace}kt_response", $response));
  456 + $this->setResponse($response);
459 457 return;
460 458 }
461   -
462   - $result = $document->download();
  459 + $docname=$document->document->getFileName();
  460 + $result=$document->download();
463 461 if (PEAR::isError($result))
464 462 {
465   - $response['message'] = $result->getMessage();
466   - $this->setResponse(array('status_code' => 1, 'message' => $result->getMessage()));
  463 + $response['message']=$result->getMessage();
  464 + $this->setResponse(array('status_code'=>1, 'message'=>$result->getMessage()));
467 465 return;
468 466 }
469 467  
470   - $session = &$kt->get_session();
471   - $download_manager = new KTDownloadManager();
  468 + $session=&$kt->get_session();
  469 + $download_manager=new KTDownloadManager();
472 470 $download_manager->set_session($session->session);
473 471 $download_manager->cleanup();
474   - $url = $download_manager->allow_download($document);
475   -
476   - $response['status_code'] = 0;
477   - $response['message'] = $url;
478   - $response['filename'] = $docname;
  472 + $url=$download_manager->allow_download($document);
  473 + //http://ktair.dev?code=750f7a09d40a3d855f2897f417baf0bbb9a1f615&d=16&u=evm2pdkkhfagon47eh2b9slqj6
  474 + $url=split('\?',$url);
  475 + $url=$url[0].'/ktwebservice/download.php?'.$url[1];
  476 +
  477 + $response['status_code']=0;
  478 + $response['message']=$url;
  479 + $response['filename']=$docname;
479 480 $this->setResponse($response);
480 481 }
481 482  
... ... @@ -490,35 +491,35 @@ class kt extends client_service {
490 491 *
491 492 */
492 493 function checkout_document($params){
493   - $responseType = 'kt_response';
  494 + $responseType='kt_response';
494 495 $kt=&$this->KT;
495 496  
496   - $document = &$kt->get_document_by_id($params['document_id']);
  497 + $document=&$kt->get_document_by_id($params['document_id']);
497 498 if (PEAR::isError($document))
498 499 {
499 500 $this->addError("checkout_document - cannot get documentid {$params['document_id']} - " . $document->getMessage());
500   - $this->setResponse(array('status_code' => 1, 'message' => $document->getMessage()));
  501 + $this->setResponse(array('status_code'=>1, 'message'=>$document->getMessage()));
501 502 return;
502 503 }
503 504  
504   - $result = $document->checkout($params['reason']);
  505 + $result=$document->checkout($params['reason']);
505 506 if (PEAR::isError($result))
506 507 {
507 508 $this->addError($result->getMessage());
508   - $this->setResponse(array('status_code' => 1, 'message' => $result->getMessage()));
  509 + $this->setResponse(array('status_code'=>1, 'message'=>$result->getMessage()));
509 510 return;
510 511 }
511 512  
512   - $url = '';
  513 + $url='';
513 514 if ($params['download'])
514 515 {
515   - $download_manager = new KTDownloadManager();
  516 + $download_manager=new KTDownloadManager();
516 517 $download_manager->set_session($params['session_id']);
517 518 $download_manager->cleanup();
518   - $url = $download_manager->allow_download($document);
  519 + $url=$download_manager->allow_download($document);
519 520 }
520 521  
521   - $this->setResponse(array('status_code' => 0, 'message' => $url));
  522 + $this->setResponse(array('status_code'=>0, 'message'=>$url));
522 523 }
523 524  
524 525  
... ... @@ -533,43 +534,43 @@ class kt extends client_service {
533 534 * @param array $params
534 535 */
535 536 function checkin_document($params){
536   - $session_id = $this->AuthInfo['session'];
537   - $document_id = $params['document_id'];
538   - $filename = $params['filename'];
539   - $reason = $params['reason'];
540   - $tempfilename = $params['tempfilename'];
541   - $application = $this->AuthInfo['appType'];
  537 + $session_id=$this->AuthInfo['session'];
  538 + $document_id=$params['document_id'];
  539 + $filename=$params['filename'];
  540 + $reason=$params['reason'];
  541 + $tempfilename=$params['tempfilename'];
  542 + $application=$this->AuthInfo['appType'];
542 543  
543 544 $this->addDebug('Checkin',"checkin_document('$session_id',$document_id,'$filename','$reason','$tempfilename', '$application')");
544   - $kt = &$this->KT;
  545 + $kt=&$this->KT;
545 546  
546 547 // we need to add some security to ensure that people don't frig the checkin process to access restricted files.
547 548 // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome.
548   - $upload_manager = new KTUploadManager();
  549 + $upload_manager=new KTUploadManager();
549 550 if (!$upload_manager->is_valid_temporary_file($tempfilename))
550 551 {
551   - $this->setResponse(array('status_code' => 12));
  552 + $this->setResponse(array('status_code'=>12));
552 553 return;
553 554 }
554 555  
555   - $document = &$kt->get_document_by_id($document_id);
  556 + $document=&$kt->get_document_by_id($document_id);
556 557 if (PEAR::isError($document))
557 558 {
558   - $this->setResponse(array('status_code' => 13));
  559 + $this->setResponse(array('status_code'=>13));
559 560 }
560 561  
561 562 // checkin
562   - $result = $document->checkin($filename, $reason, $tempfilename, false);
  563 + $result=$document->checkin($filename, $reason, $tempfilename, false);
563 564 if (PEAR::isError($result))
564 565 {
565   - $this->setResponse(array('status_code' => 14));
  566 + $this->setResponse(array('status_code'=>14));
566 567 }
567 568  
568 569 // get status after checkin
569 570 //$this->response= $this->get_document_detail($session_id, $document_id);
570   - $detail = $document->get_detail();
571   - $detail['status_code'] = 0;
572   - $detail['message'] = '';
  571 + $detail=$document->get_detail();
  572 + $detail['status_code']=0;
  573 + $detail['message']='';
573 574  
574 575 $this->setResponse($detail);
575 576 }
... ... @@ -581,686 +582,540 @@ class kt extends client_service {
581 582 * @param unknown_type $arr
582 583 */
583 584 function add_document_with_metadata($arr){
584   - $session_id = $arr['session_id'];
  585 + $session_id=$arr['session_id'];
585 586 //error_reporting(E_ALL);
586   - $metadata = array();
587   - $packed = @json_decode($arr['metadata']);
  587 + $metadata=array();
  588 + $packed=@json_decode($arr['metadata']);
588 589  
589 590 $this->debug('Entered add_document_with_metadata');
590 591  
591   - foreach($packed as $key => $val) {
  592 + foreach($packed as $key=>$val) {
592 593 if(!is_array($metadata[$val->fieldset])) {
593   - $metadata[$val->fieldset]['fieldset'] = $val->fieldset;
594   - $metadata[$val->fieldset]['fields'] = array();
  594 + $metadata[$val->fieldset]['fieldset']=$val->fieldset;
  595 + $metadata[$val->fieldset]['fields']=array();
595 596 }
596   - $metadata[$val->fieldset]['fields'][] = array(
597   - 'name' => $val->name,
598   - 'value' => $val->value
  597 + $metadata[$val->fieldset]['fields'][]=array(
  598 + 'name'=>$val->name,
  599 + 'value'=>$val->value
599 600 );
600 601 }
601 602  
602   - $add_result = $this->add_document($arr['session_id'], $arr['folder_id'], $arr['title'], $arr['filename'], $arr['documenttype'], $arr['tempfilename'], $arr['application']);
  603 + $add_result=$this->add_document($arr['session_id'], $arr['folder_id'], $arr['title'], $arr['filename'], $arr['documenttype'], $arr['tempfilename'], $arr['application']);
603 604 $this->debug('$this->response= from add_document');
604 605  
605   - $status_code = $add_result['status_code'];
  606 + $status_code=$add_result['status_code'];
606 607 if ($status_code != 0)
607 608 {
608 609 $this->response= $add_result;
609 610 }
610   - $document_id = $add_result['document_id'];
611   - $content_id = $add_result['content_id'];
  611 + $document_id=$add_result['document_id'];
  612 + $content_id=$add_result['content_id'];
612 613  
613   - $update_result = $this->update_document_metadata($arr['session_id'], $document_id, $metadata, $arr['application'], array());
  614 + $update_result=$this->update_document_metadata($arr['session_id'], $document_id, $metadata, $arr['application'], array());
614 615 $this->debug('$this->response= from update_document_metadata');
615   - $status_code = $update_result['status_code'];
  616 + $status_code=$update_result['status_code'];
616 617 if ($status_code != 0)
617 618 {
618 619 $this->delete_document($arr['session_id'], $document_id, 'Rollback because metadata could not be added', $arr['application']);
619 620 $this->response= $update_result;
620 621 }
621 622  
622   - $kt = &$this->KT;
  623 + $kt=&$this->KT;
623 624 if (is_array($kt))
624 625 {
625   - $this->response= array('status_code' => 1);
  626 + $this->response= array('status_code'=>1);
626 627 }
627 628  
628   - $document = $kt->get_document_by_id($document_id);
629   - $result = $document->removeUpdateNotification();
  629 + $document=$kt->get_document_by_id($document_id);
  630 + $result=$document->removeUpdateNotification();
630 631 if (PEAR::isError($result))
631 632 {
632 633 // not much we can do, maybe just log!
633 634 }
634 635  
635 636  
636   - $result = $document->mergeWithLastMetadataVersion();
  637 + $result=$document->mergeWithLastMetadataVersion();
637 638 if (PEAR::isError($result))
638 639 {
639 640 // not much we can do, maybe just log!
640 641 }
641 642  
642   - $this->response= array('status_code' => 0, 'document_id' => $document_id, 'content_id' => $content_id);
  643 + $this->response= array('status_code'=>0, 'document_id'=>$document_id, 'content_id'=>$content_id);
643 644 }
644 645  
645   -}
646   -
647   -
648   -/*
649   -
650   -
651   -
652 646  
653   -
654   -
655   -
656   -
657   -
658   -
659   -
660   -
661   - function debug($str) {
662   - $this->response= true;
663   - if(!is_resource($this->dfp)) {
664   - $this->dfp = fopen("./debug.log", "a+");
  647 + function get_all_client_policies(){
  648 + $config=KTConfig::getSingleton();
  649 + $this->addDebug('KTConfig Singleton',$config);
  650 +
  651 + $policies=array('allowRememberPassword', 'captureReasonsCheckin', 'captureReasonsCheckout');
  652 +
  653 + $returnPolicies=array();
  654 +
  655 + foreach ($policies as $policy_name)
  656 + {
  657 + $policyInfo=array(
  658 + 'name'=>$policy_name,
  659 + 'value'=>serviceHelper::bool2str($config->get('addInPolicies/'.$policy_name)),
  660 + 'type'=>'boolean'
  661 + );
  662 +
  663 + $returnPolicies[$policy_name] =$policyInfo;
665 664 }
666   - fwrite($this->dfp, strftime("[DEBUG %Y-%m-%d %H:%M:%S] ").$str."\r\n");
  665 +
  666 + $languages=$this->get_languages(true);
  667 +
  668 + $metadata=array('totalProperty'=>'resultsCounter', 'root'=>'languages', 'fields'=>array('isoCode', 'language'));
  669 +
  670 + $finalArray=array();
  671 + $finalArray['metaData']=$metadata;
  672 + $finalArray['policies']=$returnPolicies;
  673 + $finalArray['languages']=$languages['languages'];
  674 + $finalArray['defaultLanguage']=$languages['defaultLanguage'];
  675 + $finalArray['resultsCounter']=$languages['count'];
  676 +
  677 +
  678 + $this->setResponse($finalArray);
  679 + return true;
  680 + }
  681 +
  682 + public function switchlang($params){
  683 + setcookie("kt_language", $params['lang'], 2147483647, '/');
667 684 }
668 685  
669 686  
  687 + function add_document_params($params){
  688 + $folder_id=$params['folder_id'];
  689 + $title=$params['title'];
  690 + $filename=$params['filename'];
  691 + $documenttype=$params['documenttype'];
  692 + $tempfilename=$params['tempfilename'];
  693 + $application=$params['application'];
670 694  
  695 + $this->addDebug('','Entered add_document');
  696 + $kt=&$this->KT;
671 697  
672   - function add_document_params($params)
673   - {
674   - $session_id = $params['session_id'];
675   - $folder_id = $params['folder_id'];
676   - $title = $params['title'];
677   - $filename = $params['filename'];
678   - $documenttype = $params['documenttype'];
679   - $tempfilename = $params['tempfilename'];
680   - $application = $params['application'];
681   -
682   - $this->debug('Entered add_document');
683   - $kt = &$this->get$this->xlateapi($session_id, $application);
684   - if (is_array($kt))
685   - {
686   - $this->response= array('status_code' => 1);
687   - }
688   - $this->debug("Got \$kt");
689   -
690   - $upload_manager = new KTUploadManager();
691   - if (!$upload_manager->is_valid_temporary_file($tempfilename))
692   - {
693   - $this->response= array('status_code' => 1);
  698 + $upload_manager=new KTUploadManager();
  699 + if (!$upload_manager->is_valid_temporary_file($tempfilename)) {
  700 + $this->addError('Temporary File Not Valid');
  701 + $this->setResponse(array('status_code'=>1));
  702 + return false;
694 703 }
695   - $this->debug('Exited is_valid_temporary file');
  704 + $this->addDebug('','Exited is_valid_temporary file');
696 705  
697   - $folder = &$kt->get_folder_by_id($folder_id);
698   - if (PEAR::isError($folder))
699   - {
700   - $this->response= array('status_code' => 1);
  706 + $folder=&$kt->get_folder_by_id($folder_id);
  707 + if (PEAR::isError($folder)){
  708 + $this->addError('Could not find Folder '.$folder_id);
  709 + $this->setResponse(array('status_code'=>1));
  710 + return false;
701 711 }
702 712  
703   - $this->debug('Exited get_folder_by_id');
  713 + $this->addDebug('','Exited get_folder_by_id');
704 714  
705   - $document = &$folder->add_document($title, $filename, $documenttype, $tempfilename);
706   - if (PEAR::isError($document))
707   - {
708   - $this->response= array('status_code' => 1);
  715 + $document=&$folder->add_document($title, $filename, $documenttype, $tempfilename);
  716 + if (PEAR::isError($document)){
  717 + $this->addError("Could add Document [title:{$title},filename:{$filename},documenttype:{$documenttype},tempfilename:{$tempfilename}]");
  718 + $this->setResponse(array('status_code'=>1));
  719 + return false;
709 720 }
710 721  
711   - $this->debug('Exited folder add_document');
  722 + $this->addDebug('','Exited folder add_document');
712 723  
713   - $detail = $document->get_detail();
714   - $detail['status_code'] = 0;
715   - $detail['message'] = '';
716   -
717   - $this->response= $detail;
  724 + $detail=$document->get_detail();
  725 + $detail['status_code']=0;
  726 + $detail['message']='';
718 727  
  728 + $this->setResponse($detail);
719 729 }
  730 +
  731 + function delete_document($session_id, $document_id, $reason, $application){
  732 + $kt=&$this->KT;
720 733  
721   -
722   - function add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $application)
723   - {
724   - $this->debug('Entered add_document');
725   - $kt = &$this->get$this->xlateapi($session_id, $application);
726   - if (is_array($kt))
727   - {
728   - $this->response= array('status_code' => 1);
  734 + $document=&$kt->get_document_by_id($document_id);
  735 + if (PEAR::isError($document)){
  736 + $this->addError("Invalid document {$document_id}");
  737 + $this->setResponse(array('status_code'=>1));
  738 + return false;
729 739 }
730   - $this->debug("Got \$kt");
731 740  
732   - $upload_manager = new KTUploadManager();
733   - if (!$upload_manager->is_valid_temporary_file($tempfilename))
734   - {
735   - $this->response= array('status_code' => 1);
  741 + $result=$document->delete($reason);
  742 + if (PEAR::isError($result)) {
  743 + $this->addError("Could not delete document {$document_id}");
  744 + $this->setResponse(array('status_code'=>1));
  745 + return false;
736 746 }
737   - $this->debug('Exited is_valid_temporary file');
738   -
739   - $folder = &$kt->get_folder_by_id($folder_id);
740   - if (PEAR::isError($folder))
741   - {
742   - $this->response= array('status_code' => 1);
743   - }
744   -
745   - $this->debug('Exited get_folder_by_id');
746   -
747   - $document = &$folder->add_document($title, $filename, $documenttype, $tempfilename);
748   - if (PEAR::isError($document))
749   - {
750   - $this->response= array('status_code' => 1);
751   - }
752   -
753   - $this->debug('Exited folder add_document');
754   -
755   - $detail = $document->get_detail();
756   - $detail['status_code'] = 0;
757   - $detail['message'] = '';
758   -
759   - $this->response= $detail;
  747 + $this->setResponse(array('status_code'=>0));
  748 + return true;
760 749 }
761 750  
762 751  
763 752  
764   - function delete_document($session_id, $document_id, $reason, $application)
765   - {
766   - $kt = &$this->get$this->xlateapi($session_id, $application );
767   - if (is_array($kt))
768   - {
769   - $this->response= array('status_code' => 1);
770   - }
771   -
772   -
773   - $document = &$kt->get_document_by_id($document_id);
774   - if (PEAR::isError($document))
775   - {
776   - $this->response= array('status_code' => 1);
777   - }
778   -
779   - $result = $document->delete($reason);
780   - if (PEAR::isError($result))
781   - {
782   - $this->response= array('status_code' => 1);
783   - }
784   - $response['status_code'] = 0;
785   -
786   - $this->response= $response;
787   -
788   - }
789   -
790   - function update_document_metadata($session_id, $document_id, $metadata, $application, $sysdata=null)
791   - {
792   - $this->debug('entered update_document_metadata');
793   - $kt = &$this->get$this->xlateapi($session_id, $application );
794   - $responseType = 'kt_response';
795   - if ($this->version >= 2)
796   - {
797   - $responseType = 'kt_document_detail';
798   - }
  753 + private function update_document_metadata($session_id, $document_id, $metadata, $application, $sysdata=null){
  754 + $this->addDebug('','entered update_document_metadata');
  755 + $kt=&$this->KT;
  756 + $responseType='kt_document_detail';
799 757  
800   - if (is_array($kt))
801   - {
802   - $this->response= array('status_code' => 1, 'kterror'=>$kt);
  758 + $document=&$kt->get_document_by_id($document_id);
  759 + if (PEAR::isError($document)){
  760 + return array('status_code'=>1, 'error'=>'Error getting document');
803 761 }
804 762  
805   - $document = &$kt->get_document_by_id($document_id);
806   - if (PEAR::isError($document))
807   - {
808   - $this->response= array('status_code' => 1, 'error'=>'Error getting document');
809   - }
810   -
811   - $result = $document->update_metadata($metadata);
812   - if (PEAR::isError($result))
813   - {
814   - $this->response= array('status_code' => 1, 'error'=>'Error updating metadata');
  763 + $result=$document->update_metadata($metadata);
  764 + if (PEAR::isError($result)){
  765 + return array('status_code'=>1, 'error'=>'Error updating metadata');
815 766 }
816 767  
817   - if ($this->version >= 2)
818   - {
819   - $result = $document->update_sysdata($sysdata);
820   - if (PEAR::isError($result))
821   - {
822   - $this->response= array('status_code' => 1, 'error'=>'Error update_sysdata');
823   - }
824   - }
825   - $response['status_code'] = 0;
826   -
827   - $this->response= array('status_code' => 0);
828   - }
829   -
830   -
831   - function get_client_policy($arr)
832   - {
833   - $policy_name = $arr['policy_name'];
834   -
835   - $config = KTConfig::getSingleton();
836   -
837   - $policy = array(
838   - 'name' => $policy_name,
839   - 'value' => bool2str($config->get($policy_name)),
840   - 'type' => 'boolean'
841   - );
842   -
843   - $response['policy'] = $policy;
844   - $response['message'] = 'Knowledgetree client policies retrieval succeeded.';
845   - $response['status_code'] = 0;
  768 + $result=$document->update_sysdata($sysdata);
  769 + if (PEAR::isError($result)){
  770 + return array('status_code'=>1, 'error'=>'Error update_sysdata');
  771 + }
846 772  
847   - $this->response= $response;
  773 + return array('status_code'=>0);
848 774 }
849 775  
850   - function get_all_client_policies()
851   - {
852   - $config = KTConfig::getSingleton();
853   -
854   - $policies = array('allowRememberPassword', 'captureReasonsCheckin', 'captureReasonsCheckout');
  776 + function get_client_policy($arr){
  777 + $policy_name=$arr['policy_name'];
855 778  
856   - $$this->response=Policies = array();
  779 + $config=KTConfig::getSingleton();
857 780  
858   - foreach ($policies as $policy_name)
859   - {
860   - $policyInfo = array(
861   - 'name' => $policy_name,
862   - 'value' => bool2str($config->get('addInPolicies/'.$policy_name)),
863   - 'type' => 'boolean'
  781 + $policy=array(
  782 + 'name'=>$policy_name,
  783 + 'value'=>serviceHelper::bool2str($config->get($policy_name)),
  784 + 'type'=>'boolean'
864 785 );
865 786  
866   - $this->response=Policies[$policy_name] = $policyInfo;
867   - }
868   -
869   - $languages = $this->get_languages();
870   -
871   - $metadata = array('totalProperty'=>'resultsCounter', 'root'=>'languages', 'fields'=>array('isoCode', 'language'));
872   -
873   - $finalArray = array();
874   - $finalArray['metaData'] = $metadata;
875   - $finalArray['policies'] = $$this->response=Policies;
876   - $finalArray['languages'] = $languages['languages'];
877   - $finalArray['defaultLanguage'] = $languages['defaultLanguage'];
878   - $finalArray['resultsCounter'] = $languages['count'];
  787 + $response['policy']=$policy;
  788 + $response['message']='Knowledgetree client policies retrieval succeeded.';
  789 + $response['status_code']=0;
879 790  
880   -
881   - $this->response= $finalArray;
  791 + $this->setResponse($response);
  792 + return true;
882 793 }
883 794  
884   - function search($arr)
885   - {
886   - $kt = &$this->get$this->xlateapi($arr['session_id'], $arr['application']);
887 795  
888   - if (is_array($kt))
889   - {
890   - $this->response= $kt;
891   - }
  796 + function search($arr){
  797 + $kt=&$this->KT;
892 798  
893   - $listing = processSearchExpression("(GeneralText contains \"".$arr['query']."\")");
  799 + $listing=processSearchExpression("(GeneralText contains \"".$arr['query']."\")");
894 800  
895   - $result = ListController::_processListing($listing, 'search', $arr);
  801 + $result=ListController::_processListing($listing, 'search', $arr);
896 802  
897 803 if(!count($result)) {
898   -
899   - $result[] = array
900   - (
901   - 'text' => $this->xlate("No results found"),
902   - 'id' => ($listing[$i]['item_type'] == 'F' ? $listing[$i]['item_type']."_" : "").$listing[$i]['id'],
903   - 'leaf' => true,
904   - 'relevance' => 0,
  804 + $result[]=array(
  805 + 'text'=>$this->xlate("No results found"),
  806 + 'id'=>($listing[$i]['item_type']=='F' ? $listing[$i]['item_type']."_" : "").$listing[$i]['id'],
  807 + 'leaf'=>true,
  808 + 'relevance'=>0,
905 809 'qtip'=> $this->xlate("Please retry your search")
906 810 );
907   - } else {
908   - $result = array_slice($result, 0, 200);
  811 + }else{
  812 + $result=array_slice($result, 0, 200);
909 813 }
910 814  
911   - $this->response= $result;
  815 + $this->setResponse($result);
  816 + return true;
912 817 }
913 818  
914   - public function update_metadata($arr)
915   - {
916   - $session_id = $arr['session_id'];
917   - $metadata = array();
918   - $packed = @json_decode($arr['metadata']);
919 819  
920   - $this->debug('Entered add_document_with_metadata');
  820 + public function update_metadata($arr){
  821 + $metadata=array();
  822 + $packed=@json_decode($arr['metadata']);
921 823  
922   - $special = array();
  824 + $this->addDebug('','Entered add_document_with_metadata');
923 825  
924   - foreach($packed as $key => $val) {
925   - if(substr($val->name,0,2) != '__') {
  826 + $special=array();
926 827  
  828 + foreach($packed as $key=>$val) {
  829 + if(substr($val->name,0,2) != '__') {
927 830 if(!is_array($metadata[$val->fieldset])) {
928   - $metadata[$val->fieldset]['fieldset'] = $val->fieldset;
929   - $metadata[$val->fieldset]['fields'] = array();
  831 + $metadata[$val->fieldset]['fieldset']=$val->fieldset;
  832 + $metadata[$val->fieldset]['fields']=array();
930 833 }
931   - $metadata[$val->fieldset]['fields'][] = array(
932   - 'name' => $val->name,
933   - 'value' => $val->value
  834 + $metadata[$val->fieldset]['fields'][]=array(
  835 + 'name'=>$val->name,
  836 + 'value'=>$val->value
934 837 );
935   - } else {
936   - $special[$val->name] = $val->value;
  838 + }else{
  839 + $special[$val->name]=$val->value;
937 840 }
938 841 }
939 842  
940   - $document_id = $arr['document_id'];
  843 + $document_id=$arr['document_id'];
941 844  
942   - $update_result = $this->update_document_metadata($arr['session_id'], $document_id, $metadata, $arr['application'], array());
943   - $this->debug('$this->response= from update_document_metadata');
944   - $status_code = $update_result['status_code'];
945   - if ($status_code != 0)
946   - {
947   - $this->response= $update_result;
  845 + $update_result=$this->update_document_metadata($arr['session_id'], $document_id, $metadata, $arr['application'], array());
  846 + $this->addDebug('','$this->response= from update_document_metadata');
  847 +
  848 + $status_code=$update_result['status_code'];
  849 + if ($status_code != 0){
  850 + $this->setResponse($update_result);
948 851 }
949 852  
950   - $kt = &$this->get$this->xlateapi($arr['session_id']);
951   - if (is_array($kt))
952   - {
953   - $this->response= $kt;
954   - }
  853 + $kt=&$this->KT;
955 854  
956 855 if(!empty($special)) {
957   -
958 856 if($document_id > 0) {
959   - $document = $kt->get_document_by_id($document_id);
  857 + $document=$kt->get_document_by_id($document_id);
960 858  
961 859 if(isset($special['__title'])) {
962 860 $this->debug("Renaming to {$special['__title']}");
963   - $res = $document->rename($special['__title']);
  861 + $res=$document->rename($special['__title']);
964 862 }
965 863 }
966 864 }
967 865  
968   - $this->response= array('status_code' => 0, 'document_id' => $document_id);
  866 + $this->setResponse(array('status_code'=>0, 'document_id'=>$document_id));
969 867 }
970 868  
971   - function check_document_title($arr)
972   - {
973   -
974   - $kt = &$this->get$this->xlateapi($arr['session_id'], $arr['application'] );
975   -
976 869  
977   - if (is_array($kt))
978   - {
979   - $this->response= array('status_code' => 1);
980   - }
981 870  
982   - $folder = $kt->get_folder_by_id($arr['folder_id']);
  871 + function check_document_title($arr){
  872 + $kt=&$this->KT;
983 873  
  874 + $folder=$kt->get_folder_by_id($arr['folder_id']);
984 875 if(PEAR::isError($folder)) {
985   - $this->response= array('status_code' => 1, 'reason' => 'No such folder');
  876 + $this->setResponse(array('status_code'=>1, 'reason'=>'No such folder'));
  877 + return false;
986 878 }
987 879  
988   - $doc = $folder->get_document_by_name($arr['title']);
989   -
  880 + $doc=$folder->get_document_by_name($arr['title']);
990 881 if(PEAR::isError($doc)) {
991   - $this->response= array('status_code' => 1, 'reason' => 'No document with that title '.$arr['title']);
  882 + $this->setResponse(array('status_code'=>1, 'reason'=>'No document with that title '.$arr['title']));
  883 + return false;
992 884 }
993 885  
994   - $this->response= array('status_code' => 0);
  886 + $this->setResponse(array('status_code'=>0));
  887 + return true;
995 888 }
996 889  
997 890  
998   - //$session_id, $document_id, $reason
999   - function cancel_checkout($params)
1000   - {
1001   - //$this->debug("undo_document_checkout({$params['session_id']}, {$params['document_id']}, {$params['reason']})");
1002   -
1003   - $kt = &$this->get$this->xlateapi($params['session_id'], $params['application'] );
1004   - if (is_array($kt))
1005   - {
1006   - $this->response= array('status_code' => 1);
1007   - }
  891 + function cancel_checkout($params){
  892 + $kt=&$this->KT;
1008 893  
1009   - $document = &$kt->get_document_by_id($params['document_id']);
1010   - if (PEAR::isError($document))
1011   - {
1012   - $this->response= array('status_code' => 1, 'message' => $document->getMessage());
  894 + $document=&$kt->get_document_by_id($params['document_id']);
  895 + if (PEAR::isError($document)){
  896 + $this->setResponse(array('status_code'=>1, 'message'=>$document->getMessage()));
  897 + return false;
1013 898 }
1014 899  
1015   - $result = $document->undo_checkout($params['reason']);
1016   - if (PEAR::isError($result))
1017   - {
1018   - $this->response= array('status_code' => 1, 'message' => $result->getMessage());
  900 + $result=$document->undo_checkout($params['reason']);
  901 + if (PEAR::isError($result)){
  902 + $this->setResponse(array('status_code'=>1, 'message'=>$result->getMessage()));
  903 + return false;
1019 904 }
1020   -
1021   - $response['status_code'] = 0;
1022   -
1023   - $this->response= $response;
  905 + $response['status_code']=0;
  906 + $this->setResponse($response);
1024 907 }
1025 908  
1026   - function get_users_groups($params)
1027   - {
1028   - $kt = &$this->get$this->xlateapi($params['session_id'],$params['application'] );
1029   - if (is_array($kt))
1030   - {
1031   - $this->response= array('status_code' => 1);
1032   - }
1033   -
1034   - $query = $params['query'];
1035   - //$start = $params['start'];
1036   - //$page = $params['page'];
1037 909  
1038   - $results = KTAPI_User::getList('name LIKE "%'.$query.'%" AND id>0');
1039   -
1040   - $$this->response=Array = array();
1041   -
1042   - if (count($results) > 0) {
1043   - foreach ($results as $user)
1044   - {
1045   - $$this->response=Array[] = array('emailid'=>'u_'.$user->getId(), 'name'=> $user->getName(), 'to'=>preg_replace('/('.$query.')/i', '<b>${0}</b>', $user->getName()));
  910 + public function get_users_groups($params){
  911 + $kt=&$this->KT;
  912 + $query=$params['query'];
  913 + //$start=$params['start'];
  914 + //$page=$params['page'];
  915 +
  916 + $results=KTAPI_User::getList('name LIKE "%'.$query.'%" AND id>0');
  917 + $returnArray=array();
  918 + if (count($results) > 0){
  919 + foreach ($results as $user){
  920 + $returnArray[]=array('emailid'=>'u_'.$user->getId(), 'name'=> $user->getName(), 'to'=>preg_replace('/('.$query.')/i', '<b>${0}</b>', $user->getName()));
1046 921 }
1047 922 }
1048   -
1049   - $groups = KTAPI_Group::getList('name LIKE "%'.$query.'%"');
1050   -
1051   - if (count($groups) > 0) {
1052   - foreach ($groups as $group)
1053   - {
1054   - $$this->response=Array[] = array('emailid'=>'g_'.$group->getId(), 'name'=> $group->getName(), 'to'=>preg_replace('/('.$query.')/i', '<b>${0}</b>', $group->getName()));
  923 +
  924 + $groups=KTAPI_Group::getList('name LIKE "%'.$query.'%"');
  925 + if (count($groups) > 0){
  926 + foreach ($groups as $group){
  927 + $returnArray[]=array('emailid'=>'g_'.$group->getId(), 'name'=> $group->getName(), 'to'=>preg_replace('/('.$query.')/i', '<b>${0}</b>', $group->getName()));
1055 928 }
1056 929 }
1057   -
1058   -
1059   - $sendArray = array ('emails'=>$$this->response=Array, 'metaData'=>array('count'=>count($finalArray), 'root'=>'emails', fields=>array('name', 'to', 'emailid')));
1060   -
1061   - $this->response= $sendArray;
1062   -
1063   -
1064   -
  930 +
  931 + $sendArray=array ('emails'=>$returnArray, 'metaData'=>array('count'=>count($finalArray), 'root'=>'emails', fields=>array('name', 'to', 'emailid')));
  932 + $this->setResponse($sendArray);
  933 + return true;
1065 934 }
1066   -
1067   - function send_email($params)
1068   - {
1069   - $kt = &$this->get$this->xlateapi($params['session_id'], $params['application'] );
1070   - if (is_array($kt))
1071   - {
1072   - $this->response= array('status_code' => 1);
1073   - }
1074   -
1075   -
1076   - $message = $params['message'];
1077   - $list = $params['users'];
1078   -
1079   -
1080   - $recipientsList = array();
1081   -
1082   - $list = explode(',', $list);
1083   -
1084   - foreach ($list as $recipient)
1085   - {
1086   - if (trim($recipient) != '') { // check that value is present
1087   -
  935 +
  936 +
  937 + function send_email($params){
  938 + $kt=&$this->KT;
  939 +
  940 + $message=$params['message'];
  941 + $list=$params['users'];
  942 + $list=explode(',', $list);
  943 +
  944 + $recipientsList=array();
  945 +
  946 + foreach ($list as $recipient){
  947 + if (trim($recipient) != ''){ // check that value is present
1088 948 // if @ sign is present, signifies email address
1089   - if(strpos($recipient, '@') === false) {
1090   - // Not email
1091   - $recipient = trim($recipient);
1092   -
1093   - switch (substr($recipient, 0, 2))
1094   - {
  949 + if(strpos($recipient, '@') === false) {
  950 + $recipient=trim($recipient);
  951 + switch (substr($recipient, 0, 2)){
1095 952 case 'u_':
1096   - $id = substr($recipient, 2);
1097   - $user = KTAPI_User::getById($id);
1098   -
1099   - if ($user != null) {
1100   - $recipientsList[] = $user;
  953 + $id=substr($recipient, 2);
  954 + $user=KTAPI_User::getById($id);
  955 + if ($user != null){
  956 + $recipientsList[]=$user;
1101 957 }
1102   -
1103 958 break;
1104 959 case 'g_':
1105   - $id = substr($recipient, 2);
1106   - $group = KTAPI_Group::getById($id);
1107   -
  960 + $id=substr($recipient, 2);
  961 + $group=KTAPI_Group::getById($id);
1108 962 if ($group != null) {
1109   - $recipientsList[] = $group;
  963 + $recipientsList[]=$group;
1110 964 }
1111 965 break;
1112 966 }
1113   -
1114   - } else { // Email - just add to list
1115   - $recipientsList[] = trim($recipient);
  967 + }else{ // Email - just add to list
  968 + $recipientsList[]=trim($recipient);
1116 969 }
1117 970 }
1118 971 }
1119   -
1120   - $document = $kt->get_document_by_id($params['document']);
1121   -
1122   -
1123   - if (count($recipientsList) == 0) {
1124   - $this->response= array('status'=>'norecipients');
1125   - } else {
  972 +
  973 + $document=$kt->get_document_by_id($params['document']);
  974 + if (count($recipientsList)==0) {
  975 + $this->setResponse(array('status'=>'norecipients'));
  976 + return false;
  977 + }else{
1126 978 $document->email($recipientsList, $message, TRUE); // true to attach document
1127   - $this->response= array('status'=>'documentemailed');
  979 + $this->setResponse(array('status'=>'documentemailed'));
1128 980 }
1129   -
1130   -
  981 + return true;
1131 982 }
1132 983  
1133 984  
1134   - function is_latest_version($params)
1135   - {
  985 + function is_latest_version($params){
1136 986 $kt=&$this->KT;
1137   -
1138   -
1139   - if (is_array($kt))
1140   - {
1141   - $this->response= $kt;
1142   - }
1143   -
1144   - $documentId = $params['document_id'];
1145   - $contentId = $params['content_id'];
1146   -
1147   - $result = $kt->is_latest_version($documentId, $contentId);
1148   -
1149   - $this->response= $result;
1150   -
  987 +
  988 + $documentId=$params['document_id'];
  989 + $contentId=$params['content_id'];
  990 +
  991 + $result=$kt->is_latest_version($documentId, $contentId);
  992 +
  993 + $this->setResponse($result);
  994 + return true;
1151 995 }
1152   -
1153   - function check_permission($params)
1154   - {
  996 +
  997 + function check_permission($params){
1155 998 $kt=&$this->KT;
1156   -
1157   -
1158   - if (is_array($kt))
1159   - {
1160   - $this->response= $kt;
1161   - }
1162   -
1163   - $user = $kt->get_user();
1164   -
1165   - $document = $kt->get_document_by_id($params['document_id']);
1166   -
1167   - $folder = &$kt->get_folder_by_id($document->ktapi_folder->folderid);
1168   -
1169   - $folderDetail = $folder->get_detail();
1170   -
1171   - $permissions = $folderDetail['permissions'];
1172   -
1173   - if ($user->getId() == $document->document->getCheckedOutUserID()) {
  999 +
  1000 + $user=$kt->get_user();
  1001 + $document=$kt->get_document_by_id($params['document_id']);
  1002 + $folder=&$kt->get_folder_by_id($document->ktapi_folder->folderid);
  1003 + $folderDetail=$folder->get_detail();
  1004 + $permissions=$folderDetail['permissions'];
  1005 + if ($user->getId()==$document->document->getCheckedOutUserID()){
1174 1006 $permissions .= 'E';
1175 1007 }
1176   -
1177   - $this->response= array('status_code'=>0, 'permissions'=>$permissions);
1178   - //$this->response= $permissions;
  1008 +
  1009 + $this->setResponse(array('status_code'=>0, 'permissions'=>$permissions));
  1010 + return true;
1179 1011 }
1180 1012  
  1013 + function copydocument($params){
  1014 + $kt=&$this->KT;
1181 1015  
1182   - function renamefolder($params)
1183   - {
1184   - $kt = &$this->get$this->xlateapi($params['session_id'], $params['application'] );
1185   - if (is_array($kt))
1186   - {
1187   - $this->response= array('status_code' => 1);
1188   - }
1189   -
1190   - $response = $kt->rename_folder($params['currentfolderid'], $params['newname']);
1191   -
1192   - if ($response['status_code'] == 0) {
1193   - $this->response= array('status_code' => 0, 'status'=>'folderupdated', 'icon'=>'success', 'title'=>$this->xlate('Folder Renamed'), 'message'=>$this->xlate('Folder has been successfully renamed'));
1194   - } else {
1195   - $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']
  1016 + $response=$kt->copy_document($params['documentid'], $params['destfolderid']);
  1017 + if ($response['status_code']==0) {
  1018 + $this->setResponse(array('status_code'=>0, 'status'=>'itemupdated', 'icon'=>'success', 'title'=>$this->xlate('Document Copied'), 'message'=>$this->xlate('Document has been successfully copied')));
  1019 + return true;
  1020 + }else{
  1021 + $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to copy document'), 'message'=>$this->xlate('Unable to copy document')));
  1022 + return false;
1196 1023 }
1197   -
1198 1024 }
1199 1025  
1200   - function addfolder($params)
1201   - {
1202   - $kt = &$this->get$this->xlateapi($params['session_id'], $params['application'] );
1203   - if (is_array($kt))
1204   - {
1205   - $this->response= array('status_code' => 1);
1206   - }
1207   -
1208   -
1209   - $response = $kt->create_folder($params['currentfolderid'], $params['newname']);
  1026 + function movedocument($params){
  1027 + $kt=$this->KT;
1210 1028  
1211   - if ($response['status_code'] == 0) {
1212   - $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']);//
1213   - } else {
1214   - $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']
  1029 + $response=$kt->move_document($params['documentid'], $params['destfolderid']);
  1030 + if ($response['status_code']==0) {
  1031 + $this->setResponse(array('status_code'=>0, 'status'=>'itemupdated', 'icon'=>'success', 'title'=>$this->xlate('Document Moved'), 'message'=>$this->xlate('Document has been successfully moved')));
  1032 + return true;
  1033 + }else{
  1034 + $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to move document'), 'message'=>$this->xlate('Unable to move document')));
  1035 + return false;
1215 1036 }
1216   -
  1037 +
1217 1038 }
1218   -
1219   - function deletefolder($params)
1220   - {
1221   - $kt = &$this->get$this->xlateapi($params['session_id'], $params['application'] );
1222   - if (is_array($kt))
1223   - {
1224   - $this->response= array('status_code' => 1);
  1039 +
  1040 + function copyfolder($params){
  1041 + $kt=&$this->KT;
  1042 +
  1043 + $response=$kt->copy_folder($params['sourcefolderid'], $params['destfolderid']);
  1044 + if ($response['status_code']==0) {
  1045 + $this->setResponse(array('status_code'=>0, 'status'=>'itemupdated', 'icon'=>'success', 'title'=>$this->xlate('Folder Copied'), 'message'=>$this->xlate('Folder has been successfully copied')));
  1046 + return true;
  1047 + }else{
  1048 + $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to copy folder'), 'message'=>$this->xlate('Unable to copy folder')));
  1049 + return false;
1225 1050 }
  1051 +
  1052 + }
1226 1053  
1227   - $response = $kt->delete_folder($params['folderid'], 'Deleted from office addin');
  1054 + function movefolder($params){
  1055 + $kt=&$this->KT;
1228 1056  
1229   - if ($response['status_code'] == 0) {
1230   - $this->response= array('status_code' => 0, 'status'=>'folderdeleted', 'icon'=>'success', 'title'=>$this->xlate('Folder Deleted'), 'message'=>$this->xlate('Folder has been successfully deleted'));
1231   - } else {
1232   - $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']
  1057 + $response=$kt->move_folder($params['sourcefolderid'], $params['destfolderid']);
  1058 + if ($response['status_code']==0) {
  1059 + $this->setResponse(array('status_code'=>0, 'status'=>'itemupdated', 'icon'=>'success', 'title'=>$this->xlate('Folder Moved'), 'message'=>$this->xlate('Folder has been successfully moved')));
  1060 + return true;
  1061 + }else{
  1062 + $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to move folder'), 'message'=>$this->xlate('Unable to move folder')));
  1063 + return false;
1233 1064 }
1234   -
1235 1065 }
1236 1066  
1237   - function candeletefolder($arr)
1238   - {
1239   - $kt = &$this->get$this->xlateapi($arr['session_id'], $arr['application']);
1240   -
1241   - if (is_array($kt))
1242   - {
1243   - $this->response= $kt;
  1067 +
  1068 + function renamefolder($params){
  1069 + $kt=&$this->KT;
  1070 +
  1071 + $response=$kt->rename_folder($params['currentfolderid'], $params['newname']);
  1072 + if ($response['status_code']==0) {
  1073 + $this->setResponse(array('status_code'=>0, 'status'=>'folderupdated', 'icon'=>'success', 'title'=>$this->xlate('Folder Renamed'), 'message'=>$this->xlate('Folder has been successfully renamed')));
  1074 + return true;
  1075 + }else{
  1076 + $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to rename folder'), 'message'=>$this->xlate('Unable to rename folder')));
  1077 + return false;
1244 1078 }
  1079 + }
1245 1080  
1246   -
1247   - $folder = &$kt->get_folder_by_id($arr['folderid']);
1248   - if (PEAR::isError($folder))
1249   - {
1250   - $response = 'error';
1251   -
1252   - $this->response= 'error 1';
  1081 + function addfolder($params) {
  1082 + $kt=&$this->KT;
  1083 + $this->addDebug('parameters',$params);
  1084 + $response=$kt->create_folder($params['currentfolderid'], $params['newname']);
  1085 + $this->setResponse($response);
  1086 + return true;
  1087 + }
  1088 +
  1089 + function deletefolder($params){
  1090 + $kt=&$this->KT;
  1091 +
  1092 + $response=$kt->delete_folder($params['folderid'], 'Deleted from office addin');
  1093 + if ($response['status_code']==0) {
  1094 + $this->setResponse(array('status_code'=>0, 'status'=>'folderdeleted', 'icon'=>'success', 'title'=>$this->xlate('Folder Deleted'), 'message'=>$this->xlate('Folder has been successfully deleted')));
  1095 + return true;
  1096 + }else{
  1097 + $this->setResponse(array('status_code'=>1, 'status'=>'error', 'icon'=>'failure', 'title'=>$this->xlate('Unable to delete folder'), 'message'=>$this->xlate('Unable to delete folder')));
  1098 + return false;
1253 1099 }
1254   -
1255   -
1256   - $listing = $folder->get_listing(1, 'DF');
1257   -
1258   - if (count($listing) == 0) {
1259   - $this->response= array('status_code' => 0, 'candelete'=>TRUE);
1260   - } else {
1261   - $this->response= array('status_code' => 0, 'candelete'=>FALSE);
  1100 + }
  1101 +
  1102 + function candeletefolder($arr){
  1103 + $kt=&$this->KT;
  1104 +
  1105 + $folder=&$kt->get_folder_by_id($arr['folderid']);
  1106 + if (PEAR::isError($folder)){
  1107 + $this->setResponse('error 1');
  1108 + return false;
  1109 + }
  1110 +
  1111 + $listing=$folder->get_listing(1, 'DF');
  1112 + if (count($listing)==0) {
  1113 + $this->setResponse(array('status_code'=>0, 'candelete'=>TRUE));
  1114 + return true;
  1115 + }else{
  1116 + $this->setResponse(array('status_code'=>0, 'candelete'=>FALSE));
  1117 + return true;
1262 1118 }
1263 1119 }
1264   -
1265   -*/
  1120 +}
1266 1121 ?>
1267 1122 \ No newline at end of file
... ...
webservice/clienttools/services/3.6.1/server.php
1 1 <?php
2 2 class server extends client_service {
3 3 public function status(){
4   -
  4 + $this->setResponse(array('online'=>true));
5 5 }
6 6  
7 7 public function ping(){
... ...