Commit e18c26edcb647faf266ec8680f205ea8c62f7bef

Authored by kevin_fourie
1 parent 7d0062de

Merged in from DEV trunk...

"KTS-2121"
"ldap plugin not validating username correctly"
Fixed.

Reviewed By: Kevin Fourie

WSA-3
"Error occurs in >>ktws_eg_folder_listing.php<<"
Fixed. Rewrote get_listing() to accomodate anonymous.

Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@6824 c91229c3-7414-0410-bfa2-8a42b809f60b
ktapi/KTAPIConstants.inc.php
@@ -68,5 +68,6 @@ define(&#39;KTAPI_PERMISSION_RENAME_FOLDER&#39;, &#39;ktcore.permissions.folder_rename&#39;); @@ -68,5 +68,6 @@ define(&#39;KTAPI_PERMISSION_RENAME_FOLDER&#39;, &#39;ktcore.permissions.folder_rename&#39;);
68 define('KTAPI_PERMISSION_CHANGE_OWNERSHIP', 'ktcore.permissions.security'); 68 define('KTAPI_PERMISSION_CHANGE_OWNERSHIP', 'ktcore.permissions.security');
69 define('KTAPI_PERMISSION_DOCUMENT_MOVE', 'ktcore.permissions.write'); 69 define('KTAPI_PERMISSION_DOCUMENT_MOVE', 'ktcore.permissions.write');
70 define('KTAPI_PERMISSION_WORKFLOW', 'ktcore.permissions.workflow'); 70 define('KTAPI_PERMISSION_WORKFLOW', 'ktcore.permissions.workflow');
  71 +define('KTAPI_PERMISSION_VIEW_FOLDER', 'ktcore.permissions.folder_details');
71 72
72 ?> 73 ?>
73 \ No newline at end of file 74 \ No newline at end of file
ktapi/KTAPIDocument.inc.php
@@ -237,7 +237,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -237,7 +237,7 @@ class KTAPI_Document extends KTAPI_FolderItem
237 if (PEAR::isError($user)) 237 if (PEAR::isError($user))
238 { 238 {
239 return $user; 239 return $user;
240 - } 240 + }
241 241
242 if ($this->document->getIsCheckedOut()) 242 if ($this->document->getIsCheckedOut())
243 { 243 {
@@ -267,7 +267,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -267,7 +267,7 @@ class KTAPI_Document extends KTAPI_FolderItem
267 if (PEAR::isError($user)) 267 if (PEAR::isError($user))
268 { 268 {
269 return $user; 269 return $user;
270 - } 270 + }
271 271
272 DBUtil::startTransaction(); 272 DBUtil::startTransaction();
273 273
@@ -346,25 +346,25 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -346,25 +346,25 @@ class KTAPI_Document extends KTAPI_FolderItem
346 } 346 }
347 347
348 $name = $this->document->getName(); 348 $name = $this->document->getName();
349 - $clash = KTDocumentUtil::nameExists($target_folder, $name); 349 + $clash = KTDocumentUtil::nameExists($target_folder, $name);
350 if ($clash && !is_null($newname)) 350 if ($clash && !is_null($newname))
351 { 351 {
352 $name = $newname; 352 $name = $newname;
353 $clash = KTDocumentUtil::nameExists($target_folder, $name); 353 $clash = KTDocumentUtil::nameExists($target_folder, $name);
354 - } 354 + }
355 if ($clash) 355 if ($clash)
356 { 356 {
357 return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.'); 357 return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.');
358 } 358 }
359 359
360 $filename=$this->document->getFilename(); 360 $filename=$this->document->getFilename();
361 - $clash = KTDocumentUtil::fileExists($target_folder, $filename); 361 + $clash = KTDocumentUtil::fileExists($target_folder, $filename);
362 362
363 if ($clash && !is_null($newname)) 363 if ($clash && !is_null($newname))
364 { 364 {
365 $filename = $newfilename; 365 $filename = $newfilename;
366 - $clash = KTDocumentUtil::fileExists($target_folder, $filename);  
367 - } 366 + $clash = KTDocumentUtil::fileExists($target_folder, $filename);
  367 + }
368 if ($clash) 368 if ($clash)
369 { 369 {
370 return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.'); 370 return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.');
@@ -435,7 +435,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -435,7 +435,7 @@ class KTAPI_Document extends KTAPI_FolderItem
435 if (PEAR::isError($user)) 435 if (PEAR::isError($user))
436 { 436 {
437 return $user; 437 return $user;
438 - } 438 + }
439 439
440 if ($this->document->getIsCheckedOut()) 440 if ($this->document->getIsCheckedOut())
441 { 441 {
@@ -457,25 +457,25 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -457,25 +457,25 @@ class KTAPI_Document extends KTAPI_FolderItem
457 } 457 }
458 458
459 $name = $this->document->getName(); 459 $name = $this->document->getName();
460 - $clash = KTDocumentUtil::nameExists($target_folder, $name); 460 + $clash = KTDocumentUtil::nameExists($target_folder, $name);
461 if ($clash && !is_null($newname)) 461 if ($clash && !is_null($newname))
462 { 462 {
463 $name = $newname; 463 $name = $newname;
464 $clash = KTDocumentUtil::nameExists($target_folder, $name); 464 $clash = KTDocumentUtil::nameExists($target_folder, $name);
465 - } 465 + }
466 if ($clash) 466 if ($clash)
467 { 467 {
468 return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the moved document.'); 468 return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the moved document.');
469 } 469 }
470 470
471 $filename=$this->document->getFilename(); 471 $filename=$this->document->getFilename();
472 - $clash = KTDocumentUtil::fileExists($target_folder, $filename); 472 + $clash = KTDocumentUtil::fileExists($target_folder, $filename);
473 473
474 if ($clash && !is_null($newname)) 474 if ($clash && !is_null($newname))
475 { 475 {
476 $filename = $newfilename; 476 $filename = $newfilename;
477 - $clash = KTDocumentUtil::fileExists($target_folder, $filename);  
478 - } 477 + $clash = KTDocumentUtil::fileExists($target_folder, $filename);
  478 + }
479 if ($clash) 479 if ($clash)
480 { 480 {
481 return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the moved document.'); 481 return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the moved document.');
@@ -516,7 +516,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -516,7 +516,7 @@ class KTAPI_Document extends KTAPI_FolderItem
516 if (PEAR::isError($user)) 516 if (PEAR::isError($user))
517 { 517 {
518 return $user; 518 return $user;
519 - } 519 + }
520 520
521 DBUtil::startTransaction(); 521 DBUtil::startTransaction();
522 $res = KTDocumentUtil::rename($this->document, $newname, $user); 522 $res = KTDocumentUtil::rename($this->document, $newname, $user);
@@ -525,7 +525,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -525,7 +525,7 @@ class KTAPI_Document extends KTAPI_FolderItem
525 DBUtil::rollback(); 525 DBUtil::rollback();
526 return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); 526 return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res );
527 } 527 }
528 - DBUtil::commit(); 528 + DBUtil::commit();
529 } 529 }
530 530
531 /** 531 /**
@@ -540,7 +540,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -540,7 +540,7 @@ class KTAPI_Document extends KTAPI_FolderItem
540 if (PEAR::isError($user)) 540 if (PEAR::isError($user))
541 { 541 {
542 return $user; 542 return $user;
543 - } 543 + }
544 544
545 $doctypeid = KTAPI::get_documenttypeid($documenttype); 545 $doctypeid = KTAPI::get_documenttypeid($documenttype);
546 546
@@ -571,7 +571,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -571,7 +571,7 @@ class KTAPI_Document extends KTAPI_FolderItem
571 if (PEAR::isError($user)) 571 if (PEAR::isError($user))
572 { 572 {
573 return $user; 573 return $user;
574 - } 574 + }
575 575
576 if ($this->document->getName() != $newname) 576 if ($this->document->getName() != $newname)
577 { 577 {
@@ -753,7 +753,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -753,7 +753,7 @@ class KTAPI_Document extends KTAPI_FolderItem
753 { 753 {
754 if ($fieldset->getIsConditional()) { /* this is not implemented...*/ continue; } 754 if ($fieldset->getIsConditional()) { /* this is not implemented...*/ continue; }
755 755
756 - $fields = $fieldset->getFields(); 756 + $fields = $fieldset->getFields();
757 $result = array('fieldset' => $fieldset->getName(), 757 $result = array('fieldset' => $fieldset->getName(),
758 'description' => $fieldset->getDescription()); 758 'description' => $fieldset->getDescription());
759 759
@@ -761,7 +761,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -761,7 +761,7 @@ class KTAPI_Document extends KTAPI_FolderItem
761 761
762 foreach ($fields as $field) 762 foreach ($fields as $field)
763 { 763 {
764 - $value = 'n/a'; 764 + $value = 'n/a';
765 765
766 $fieldvalue = DocumentFieldLink::getByDocumentAndField($this->document, $field); 766 $fieldvalue = DocumentFieldLink::getByDocumentAndField($this->document, $field);
767 if (!is_null($fieldvalue) && (!PEAR::isError($fieldvalue))) 767 if (!is_null($fieldvalue) && (!PEAR::isError($fieldvalue)))
@@ -777,12 +777,12 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -777,12 +777,12 @@ class KTAPI_Document extends KTAPI_FolderItem
777 { 777 {
778 $controltype = 'tree'; 778 $controltype = 'tree';
779 } 779 }
780 - } 780 + }
781 781
782 switch ($controltype) 782 switch ($controltype)
783 { 783 {
784 case 'lookup': 784 case 'lookup':
785 - $selection = KTAPI::get_metadata_lookup($field->getId()); 785 + $selection = KTAPI::get_metadata_lookup($field->getId());
786 break; 786 break;
787 case 'tree': 787 case 'tree':
788 $selection = KTAPI::get_metadata_tree($field->getId()); 788 $selection = KTAPI::get_metadata_tree($field->getId());
@@ -807,7 +807,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -807,7 +807,7 @@ class KTAPI_Document extends KTAPI_FolderItem
807 $results [] = $result; 807 $results [] = $result;
808 } 808 }
809 809
810 - return $results; 810 + return $results;
811 } 811 }
812 812
813 /** 813 /**
@@ -817,28 +817,60 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -817,28 +817,60 @@ class KTAPI_Document extends KTAPI_FolderItem
817 */ 817 */
818 function update_metadata($metadata) 818 function update_metadata($metadata)
819 { 819 {
  820 + global $default;
820 $packed = array(); 821 $packed = array();
821 822
822 foreach($metadata as $fieldset_metadata) 823 foreach($metadata as $fieldset_metadata)
823 { 824 {
824 - $fieldsetname=$fieldset_metadata['fieldset']; 825 + if (is_array($fieldset_metadata))
  826 + {
  827 + $fieldsetname=$fieldset_metadata['fieldset'];
  828 + $fields=$fieldset_metadata['fields'];
  829 + }
  830 + elseif (is_a($fieldset_metadata, 'stdClass'))
  831 + {
  832 + $fieldsetname=$fieldset_metadata->fieldset;
  833 + $fields=$fieldset_metadata->fields;
  834 + }
  835 + else
  836 + {
  837 + $default->log->debug("unexpected fieldset type");
  838 + continue;
  839 + }
  840 +
825 $fieldset = KTFieldset::getByName($fieldsetname); 841 $fieldset = KTFieldset::getByName($fieldsetname);
826 if (is_null($fieldset) || PEAR::isError($fieldset)) 842 if (is_null($fieldset) || PEAR::isError($fieldset))
827 { 843 {
  844 + $default->log->debug("could not resolve fieldset: $fieldsetname");
828 // exit graciously 845 // exit graciously
829 continue; 846 continue;
830 } 847 }
831 848
832 - foreach($fieldset_metadata['fields'] as $fieldinfo) 849 + foreach($fields as $fieldinfo)
833 { 850 {
834 - $fieldname = $fieldinfo['name']; 851 + if (is_array($fieldinfo))
  852 + {
  853 + $fieldname = $fieldinfo['name'];
  854 + $value = $fieldinfo['value'];
  855 + }
  856 + elseif (is_a($fieldinfo, 'stdClass'))
  857 + {
  858 + $fieldname = $fieldinfo->name;
  859 + $value = $fieldinfo->value;
  860 + }
  861 + else
  862 + {
  863 + $default->log->debug("unexpected fieldinfo type");
  864 + continue;
  865 + }
  866 +
835 $field = DocumentField::getByFieldsetAndName($fieldset, $fieldname); 867 $field = DocumentField::getByFieldsetAndName($fieldset, $fieldname);
836 if (is_null($field) || PEAR::isError($fieldset)) 868 if (is_null($field) || PEAR::isError($fieldset))
837 { 869 {
  870 + $default->log->debug("could not resolve field: $fieldname");
838 // exit graciously 871 // exit graciously
839 continue; 872 continue;
840 - }  
841 - $value = $fieldinfo['value']; 873 + }
842 874
843 $packed[] = array($field, $value); 875 $packed[] = array($field, $value);
844 } 876 }
@@ -890,7 +922,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -890,7 +922,7 @@ class KTAPI_Document extends KTAPI_FolderItem
890 } 922 }
891 foreach($transitions as $transition) 923 foreach($transitions as $transition)
892 { 924 {
893 - $result[] = $transition->getName(); 925 + $result[] = $transition->getName();
894 } 926 }
895 927
896 return $result; 928 return $result;
@@ -1042,7 +1074,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -1042,7 +1074,7 @@ class KTAPI_Document extends KTAPI_FolderItem
1042 function download($version=null) 1074 function download($version=null)
1043 { 1075 {
1044 $storage =& KTStorageManagerUtil::getSingleton(); 1076 $storage =& KTStorageManagerUtil::getSingleton();
1045 - $options = array(); 1077 + $options = array();
1046 1078
1047 1079
1048 $oDocumentTransaction = & new DocumentTransaction($this->document, 'Document downloaded', 'ktcore.transactions.download', $aOptions); 1080 $oDocumentTransaction = & new DocumentTransaction($this->document, 'Document downloaded', 'ktcore.transactions.download', $aOptions);
@@ -1091,7 +1123,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -1091,7 +1123,7 @@ class KTAPI_Document extends KTAPI_FolderItem
1091 $user = User::get($userid); 1123 $user = User::get($userid);
1092 1124
1093 $version['user'] = $user->getName(); 1125 $version['user'] = $user->getName();
1094 - $version['metadata_version'] = $document->getMetadataVersion(); 1126 + $version['metadata_version'] = $document->getMetadataVersion();
1095 $version['content_version'] = $document->getVersion(); 1127 $version['content_version'] = $document->getVersion();
1096 1128
1097 $versions[] = $version; 1129 $versions[] = $version;
@@ -1143,7 +1175,7 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -1143,7 +1175,7 @@ class KTAPI_Document extends KTAPI_FolderItem
1143 { 1175 {
1144 $this->document->setFolderId(1); 1176 $this->document->setFolderId(1);
1145 $folder = Folder::get(1); 1177 $folder = Folder::get(1);
1146 - } 1178 + }
1147 else 1179 else
1148 { 1180 {
1149 $this->document->setFolderId($this->document->getRestoreFolderId()); 1181 $this->document->setFolderId($this->document->getRestoreFolderId());
ktapi/KTAPIFolder.inc.php
@@ -232,127 +232,161 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -232,127 +232,161 @@ class KTAPI_Folder extends KTAPI_FolderItem
232 return $this->_get_document_by_name($documentname,'getByFilenameAndFolder'); 232 return $this->_get_document_by_name($documentname,'getByFilenameAndFolder');
233 } 233 }
234 234
235 - function get_listing($depth=1, $what='DF') 235 + function _resolve_user($userid)
236 { 236 {
  237 + $user=null;
  238 +
  239 + if (!is_null($userid))
  240 + {
  241 + $user=User::get($userid);
  242 + if (is_null($user) || PEAR::isError($user))
  243 + {
  244 + $user=null;
  245 + }
  246 + }
  247 + return $user;
  248 + }
  249 +
  250 +
  251 + function get_listing($depth=1, $what='DF')
  252 + {
237 if ($depth < 1) 253 if ($depth < 1)
238 { 254 {
239 return array(); 255 return array();
240 } 256 }
241 - $permission = &KTPermission::getByName(KTAPI_PERMISSION_READ);  
242 - $permissionid= $permission->getId();  
243 257
244 - $user = $this->ktapi->get_user();  
245 - $descriptors=KTPermissionUtil::getPermissionDescriptorsForUser($user);  
246 - if (is_null($descriptors) || PEAR::isError($descriptors))  
247 - {  
248 - return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR . ': problem with descriptors for user', $descriptors);  
249 - }  
250 - if (count($descriptors == 0))  
251 - {  
252 - $descriptors=array(0);  
253 - } 258 + $what = strtoupper($what);
  259 + $read_permission = &KTPermission::getByName(KTAPI_PERMISSION_READ);
  260 + $folder_permission = &KTPermission::getByName(KTAPI_PERMISSION_VIEW_FOLDER);
  261 +
254 262
255 - $aPermissionDescriptors = implode(',',$descriptors); 263 + $user = $this->ktapi->get_user();
  264 +
  265 + $contents = array();
256 266
257 - $sql = '';  
258 - if (strpos($what,'D') !== false)  
259 - {  
260 - $sql .= "SELECT  
261 - d.id,  
262 - 'D' as item_type,  
263 - dmv.name as title,  
264 - ifnull(uc.name, 'n/a') AS creator,  
265 - ifnull(cou.name, 'n/a') AS checkedoutby,  
266 - ifnull(mu.name, 'n/a') AS modifiedby,  
267 - dcv.filename,  
268 - dcv.size,  
269 - dcv.major_version,  
270 - dcv.minor_version,  
271 - dcv.storage_path,  
272 - ifnull(mt.mimetypes, 'unknown') as mime_type,  
273 - ifnull(mt.icon_path, 'unknown') as mime_icon_path,  
274 - ifnull(mt.friendly_name, 'unknown') as mime_display  
275 - FROM  
276 - documents d  
277 - INNER JOIN permission_lookups AS PL ON d.permission_lookup_id = PL.id  
278 - INNER JOIN permission_lookup_assignments AS PLA ON PL.id = PLA.permission_lookup_id AND PLA.permission_id = $permissionid  
279 - INNER JOIN document_metadata_version AS dmv ON d.metadata_version_id=dmv.id  
280 - INNER JOIN document_content_version AS dcv ON dmv.content_version_id=dcv.id  
281 - LEFT OUTER JOIN mime_types mt ON dcv.mime_id = mt.id  
282 - LEFT OUTER JOIN users AS uc ON d.creator_id=uc.id  
283 - LEFT OUTER JOIN users AS cou ON d.checked_out_user_id=cou.id  
284 - LEFT OUTER JOIN users AS mu ON d.modified_user_id=mu.id  
285 - WHERE  
286 - d.folder_id=$this->folderid  
287 - AND d.status_id = 1  
288 - AND PLA.permission_descriptor_id IN ($aPermissionDescriptors)";  
289 - }  
290 -  
291 if (strpos($what,'F') !== false) 267 if (strpos($what,'F') !== false)
292 { 268 {
293 - if (strpos($what,'D') !== false) 269 + $folder_children = Folder::getList(array('parent_id = ?', $this->folderid));
  270 +
  271 +
  272 + foreach ($folder_children as $folder)
294 { 273 {
295 - $sql .= ' UNION '; 274 + if(KTPermissionUtil::userHasPermissionOnItem($user, $folder_permission, $folder))
  275 + {
  276 + $creator=$this->_resolve_user($folder->getCreatorID());
  277 +
  278 + if ($depth-1 > 0)
  279 + {
  280 + $sub_folder = &$this->ktapi->get_folder_by_id($folder->getId());
  281 + $items = $folder->get_listing($depth-1);
  282 + }
  283 + else
  284 + {
  285 + $items=array();
  286 + }
  287 +
  288 +
  289 + $contents[] = array(
  290 + 'id' => (int) $folder->getId(),
  291 + 'item_type'=>'F',
  292 + 'title'=>$folder->getName(),
  293 + 'creator'=>is_null($creator)?'n/a':$creator->getName(),
  294 + 'checkedoutby'=>'n/a',
  295 + 'modifiedby'=>'n/a',
  296 + 'filename'=>$folder->getName(),
  297 + 'size'=>'n/a',
  298 + 'major_version'=>'n/a',
  299 + 'minor_version'=>'n/a',
  300 + 'storage_path'=>'n/a',
  301 + 'mime_type'=>'folder',
  302 + 'mime_icon_path'=>'folder',
  303 + 'mime_display'=>'Folder',
  304 + 'items'=>$items,
  305 + 'workflow'=>'n/a',
  306 + 'workflow_state'=>'n/a'
  307 +
  308 + );
  309 + }
296 } 310 }
297 -  
298 - $sql .= "  
299 - SELECT  
300 - f.id,  
301 - 'F' as item_type,  
302 - f.name as title,  
303 - ifnull(uc.name, 'n/a') AS creator,  
304 - 'n/a' checkedoutby,  
305 - 'n/a' AS modifiedby,  
306 - f.name as filename,  
307 - 'n/a' as size,  
308 - 'n/a' as major_version,  
309 - 'n/a' as minor_version,  
310 - 'n/a' as storage_path,  
311 - 'folder' as mime_type,  
312 - 'folder' as mime_icon_path,  
313 - 'Folder' as mime_display  
314 - FROM  
315 - folders f  
316 - INNER JOIN permission_lookups AS PL ON f.permission_lookup_id = PL.id  
317 - INNER JOIN permission_lookup_assignments AS PLA ON PL.id = PLA.permission_lookup_id AND PLA.permission_id = $permissionid  
318 - LEFT OUTER JOIN users AS uc ON f.creator_id=uc.id  
319 -  
320 - WHERE  
321 - f.parent_id=$this->folderid  
322 -  
323 - AND PLA.permission_descriptor_id IN ($aPermissionDescriptors)  
324 - ORDER BY item_type DESC, title, filename  
325 - ";  
326 - }  
327 -  
328 - $contents = DBUtil::getResultArray($sql);  
329 - if (is_null($contents) || PEAR::isError($contents))  
330 - {  
331 - return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR , $contents);  
332 } 311 }
333 -  
334 - $num_items = count($contents);  
335 - for($i=0;$i<$num_items;$i++) 312 + if (strpos($what,'D') !== false)
336 { 313 {
337 - $contents[$i]['id'] = (int) $contents[$i]['id'];  
338 - if ($contents[$i]['item_type'] == 'D')  
339 - {  
340 - $contents[$i]['items'] = array();  
341 - }  
342 - else 314 + $document_children = Document::getList(array('folder_id = ? AND status_id = 1', $this->folderid));
  315 +
  316 + // I hate that KT doesn't cache things nicely...
  317 + $mime_cache=array();
  318 +
  319 + foreach ($document_children as $document)
343 { 320 {
344 - if ($depth-1 > 0) 321 + if (KTPermissionUtil::userHasPermissionOnItem($user, $read_permission, $document))
345 { 322 {
346 - $folder = &$this->ktapi->get_folder_by_id($item['id']);  
347 - $contents[$i]['items'] = $folder->get_listing($depth-1);  
348 - }  
349 - else  
350 - {  
351 - $contents[$i]['items'] = array(); 323 + $creator=$this->_resolve_user($document->getCreatorID());
  324 + $checkedoutby=$this->_resolve_user($document->getCheckedOutUserID());
  325 + $modifiedby=$this->_resolve_user($document->getCreatorID());
  326 +
  327 + $mimetypeid=$document->getMimeTypeID();
  328 + if (!array_key_exists($mimetypeid, $mime_cache))
  329 + {
  330 +
  331 + $type=KTMime::getMimeTypeName($mimetypeid);
  332 + $icon=KTMime::getIconPath($mimetypeid);
  333 + $display=KTMime::getFriendlyNameForString($type);
  334 + $mime_cache[$mimetypeid] = array(
  335 + 'type'=>$type,
  336 + 'icon'=>$icon,
  337 + 'display'=>$display
  338 +
  339 + );
  340 + }
  341 + $mimeinfo=$mime_cache[$mimetypeid];
  342 +
  343 + $workflow = KTWorkflowUtil::getWorkflowForDocument($document);
  344 +
  345 + if (!is_null($workflow) && !PEAR::isError($workflow))
  346 + {
  347 + $workflow=$workflow->getHumanName();
  348 +
  349 + $state=KTWorkflowUtil::getWorkflowStateForDocument($document);
  350 + if (!is_null($state) && !PEAR::isError($state))
  351 + {
  352 + $state=$state->getHumanName();
  353 + }
  354 + else
  355 + {
  356 + $state='n/a';
  357 + }
  358 + }
  359 + else
  360 + {
  361 + $workflow='n/a';
  362 + $state='n/a';
  363 + }
  364 +
  365 +
  366 + $contents[] = array(
  367 + 'id' => (int) $document->getId(),
  368 + 'item_type'=>'D',
  369 + 'title'=>$document->getName(),
  370 + 'creator'=>is_null($creator)?'n/a':$creator->getName(),
  371 + 'checkedoutby'=>is_null($checkedoutby)?'n/a':$checkedoutby->getName(),
  372 + 'modifiedby'=>is_null($modifiedby)?'n/a':$modifiedby->getName(),
  373 + 'filename'=>$document->getName(),
  374 + 'size'=>$document->getFileSize(),
  375 + 'major_version'=>$document->getMajorVersionNumber(),
  376 + 'minor_version'=>$document->getMinorVersionNumber(),
  377 + 'storage_path'=>$document->getStoragePath(),
  378 + 'mime_type'=>$mime_cache[$mimetypeid]['type'],
  379 + 'mime_icon_path'=>$mime_cache[$mimetypeid]['icon'],
  380 + 'mime_display'=>$mime_cache[$mimetypeid]['display'],
  381 + 'items'=>array(),
  382 + 'workflow'=>$workflow,
  383 + 'workflow_state'=>$state
  384 + );
352 } 385 }
353 } 386 }
  387 +
354 } 388 }
355 - 389 +
356 return $contents; 390 return $contents;
357 } 391 }
358 392
ktapi/KTAPISession.inc.php
@@ -266,7 +266,11 @@ class KTAPI_UserSession extends KTAPI_Session @@ -266,7 +266,11 @@ class KTAPI_UserSession extends KTAPI_Session
266 $sql = "UPDATE active_sessions SET last_used='$now' WHERE id=$sessionid"; 266 $sql = "UPDATE active_sessions SET last_used='$now' WHERE id=$sessionid";
267 DBUtil::runQuery($sql); 267 DBUtil::runQuery($sql);
268 268
269 - $session = &new KTAPI_UserSession($ktapi, $user, $session, $sessionid, $ip); 269 +
  270 + if ($user->isAnonymous())
  271 + $session = &new KTAPI_AnonymousSession($ktapi, $user, $session, $sessionid, $ip);
  272 + else
  273 + $session = &new KTAPI_UserSession($ktapi, $user, $session, $sessionid, $ip);
270 return $session; 274 return $session;
271 } 275 }
272 276
ktwebservice/webservice.php
@@ -126,6 +126,8 @@ class KTWebService @@ -126,6 +126,8 @@ class KTWebService
126 'mime_type' => 'string', 126 'mime_type' => 'string',
127 'mime_icon_path' => 'string', 127 'mime_icon_path' => 'string',
128 'mime_display' => 'string', 128 'mime_display' => 'string',
  129 + 'workflow'=>'string',
  130 + 'workflow_state'=>'string',
129 'items' =>"{urn:$this->namespace}kt_folder_items" 131 'items' =>"{urn:$this->namespace}kt_folder_items"
130 ); 132 );
131 133
@@ -303,6 +305,13 @@ class KTWebService @@ -303,6 +305,13 @@ class KTWebService
303 array('in' => array('username' => 'string', 'password' => 'string', 'ip' => 'string'), 305 array('in' => array('username' => 'string', 'password' => 'string', 'ip' => 'string'),
304 'out' => array('return' => "{urn:$this->namespace}kt_response" ), 306 'out' => array('return' => "{urn:$this->namespace}kt_response" ),
305 ); 307 );
  308 +
  309 + // anonymous_login
  310 + $this->__dispatch_map['anonymous_login'] =
  311 + array('in' => array('ip' => 'string'),
  312 + 'out' => array('return' => "{urn:$this->namespace}kt_response" ),
  313 + );
  314 +
306 315
307 // logout 316 // logout
308 $this->__dispatch_map['logout'] = 317 $this->__dispatch_map['logout'] =
@@ -586,7 +595,36 @@ class KTWebService @@ -586,7 +595,36 @@ class KTWebService
586 } 595 }
587 return $kt; 596 return $kt;
588 } 597 }
589 - 598 +
  599 + /**
  600 + * Creates a new anonymous session.
  601 + *
  602 + * @param string $ip
  603 + * @return kt_response
  604 + */
  605 + function anonymous_login($ip=null)
  606 + {
  607 + $response = array(
  608 + 'status_code'=>KTWS_ERR_AUTHENTICATION_ERROR,
  609 + 'message'=>'',
  610 + );
  611 +
  612 + $kt = &new KTAPI();
  613 +
  614 + $session = $kt->start_anonymous_session($ip);
  615 +
  616 + if (PEAR::isError($session))
  617 + {
  618 + $response['message'] = $session->getMessage();
  619 + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  620 + }
  621 +
  622 + $response['status_code'] = KTWS_SUCCESS;
  623 + $response['message'] = $session->get_session();
  624 +
  625 + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response);
  626 + }
  627 +
590 /** 628 /**
591 * Creates a new session for the user. 629 * Creates a new session for the user.
592 * 630 *
@@ -672,7 +710,7 @@ class KTWebService @@ -672,7 +710,7 @@ class KTWebService
672 'status_code'=>KTWS_ERR_INVALID_FOLDER, 710 'status_code'=>KTWS_ERR_INVALID_FOLDER,
673 'message'=>$folder->getMessage() 711 'message'=>$folder->getMessage()
674 ); 712 );
675 - return new SOAP_Value('return',"{urn:$this->namespace}kt_folder_detail", $kt); 713 + return new SOAP_Value('return',"{urn:$this->namespace}kt_folder_detail", $response);
676 } 714 }
677 715
678 $detail = $folder->get_detail(); 716 $detail = $folder->get_detail();
@@ -810,7 +848,7 @@ class KTWebService @@ -810,7 +848,7 @@ class KTWebService
810 } 848 }
811 849
812 $listing = $folder->get_listing($depth, $what); 850 $listing = $folder->get_listing($depth, $what);
813 - 851 +
814 $contents = array( 852 $contents = array(
815 'status_code'=>KTWS_SUCCESS, 853 'status_code'=>KTWS_SUCCESS,
816 'message'=>'', 854 'message'=>'',
plugins/ktstandard/ldap/ldapbaseauthenticationprovider.inc.php
@@ -264,7 +264,7 @@ class KTLDAPBaseAuthenticationProvider extends KTAuthenticationProvider { @@ -264,7 +264,7 @@ class KTLDAPBaseAuthenticationProvider extends KTAuthenticationProvider {
264 $name = KTUtil::arrayGet($_REQUEST, 'name'); 264 $name = KTUtil::arrayGet($_REQUEST, 'name');
265 if (empty($name)) { $this->errorRedirectToMain(_kt('You must specify a name for the user.')); } 265 if (empty($name)) { $this->errorRedirectToMain(_kt('You must specify a name for the user.')); }
266 $username = KTUtil::arrayGet($_REQUEST, 'ldap_username'); 266 $username = KTUtil::arrayGet($_REQUEST, 'ldap_username');
267 - if (empty($name)) { $this->errorRedirectToMain(_kt('You must specify a new username.')); } 267 + if (empty($username)) { $this->errorRedirectToMain(_kt('You must specify a new username.')); }
268 // FIXME check for non-clashing usernames. 268 // FIXME check for non-clashing usernames.
269 269
270 $email_address = KTUtil::arrayGet($_REQUEST, 'email_address'); 270 $email_address = KTUtil::arrayGet($_REQUEST, 'email_address');