Commit 353833767dacfec1c26f7efbb68c6c789a4e21cf

Authored by Conrad Vermeulen
1 parent c798d113

KTS-2838

"Upgrade script must ensure tables are using InnoDB storage engine on mysql"
Fixed. 

KTS-2877
"Full path on document and folder in database is misleading"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Megan Watson

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7979 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/browse/browseutil.inc.php
... ... @@ -186,7 +186,7 @@ class KTBrowseUtil {
186 186 $aBreadcrumbs = array();
187 187  
188 188 // skip root.
189   - $folder_path_names = array_slice($oFolder->getPathArray(), 1);
  189 + $folder_path_names = $oFolder->getPathArray();
190 190 $folder_path_ids = array_slice(explode(',', $oFolder->getParentFolderIds()), 1);
191 191  
192 192 $parents = count($folder_path_ids);
... ...
lib/documentmanagement/documentcore.inc.php
... ... @@ -194,7 +194,20 @@ class KTDocumentCore extends KTEntity {
194 194 }
195 195 }
196 196 if (!is_null($lastFolder)) {
197   - $this->sFullPath = $lastFolder->getFullPath();
  197 + $this->sFullPath = 'pending';
  198 + if (!is_null($this->getMetadataVersionId()))
  199 + {
  200 + $metadata = KTDocumentMetadataVersion::get($this->getMetadataVersionId());
  201 + $name =$metadata->getName();
  202 + if ($lastFolder->getId() == 1)
  203 + {
  204 + $this->sFullPath = $name;
  205 + }
  206 + else
  207 + {
  208 + $this->sFullPath = $lastFolder->getFullPath() . '/' . $name;
  209 + }
  210 + }
198 211 $this->sParentFolderIds = $lastFolder->getParentFolderIDs();
199 212 }
200 213 return parent::_fieldValues();
... ...
lib/foldermanagement/Folder.inc
... ... @@ -183,8 +183,21 @@ class Folder extends KTEntity {
183 183 }
184 184  
185 185 function _fieldValues () {
186   - $this->sFullPath = Folder::generateFolderPath($this->iParentID);
187   - $this->sParentFolderIDs = $this->generateFolderIDs($this->iParentID);
  186 + if ($this->getId() == 1)
  187 + {
  188 + $this->sFullPath = null;
  189 + $this->sParentFolderIDs = null;
  190 + }
  191 + else
  192 + {
  193 + $parent = Folder::get($this->iParentID);
  194 + $this->sFullPath = $parent->getFullPath();
  195 + if (!empty($this->sFullPath)) $this->sFullPath .= '/';
  196 + $this->sFullPath .= $this->sName;
  197 + $this->sParentFolderIDs = $parent->getParentFolderIDs();
  198 + if (!empty($this->sParentFolderIDs)) $this->sParentFolderIDs .= ',';
  199 + $this->sParentFolderIDs .= $this->iParentID;
  200 + }
188 201 return parent::_fieldValues();
189 202 return array(
190 203 'name' => $this->sName,
... ... @@ -331,6 +344,8 @@ class Folder extends KTEntity {
331 344 */
332 345 function getFolderPathNamesAsArray($iFolderID) {
333 346 global $default;
  347 +
  348 +
334 349 $oFolder = Folder::get($iFolderID);
335 350 $aPathArray = array();
336 351 if ($oFolder) {
... ... @@ -340,7 +355,8 @@ class Folder extends KTEntity {
340 355 } else {
341 356 $aPathArray = array($oFolder->getFullPath());
342 357 }
343   - $aPathArray[count($aPathArray)] = $oFolder->getName();
  358 +
  359 + //$aPathArray[count($aPathArray)] = $oFolder->getName();
344 360 } else {
345 361 $aPathArray = array($oFolder->getName());
346 362 }
... ...
lib/foldermanagement/compressionArchiveUtil.inc.php
... ... @@ -76,6 +76,30 @@ class ZipFolder {
76 76 $this->aReplaceValues = array_values($aReplace);
77 77 }
78 78  
  79 + /**
  80 + * Return the full path
  81 + *
  82 + * @param mixed $oFolderOrDocument May be a Folder or Document
  83 + */
  84 + function getFullFolderPath($oFolder)
  85 + {
  86 + static $sRootFolder = null;
  87 +
  88 + if (is_null($sRootFolder))
  89 + {
  90 + $oRootFolder = Folder::get(1);
  91 + $sRootFolder = $oRootFolder->getName();
  92 + }
  93 +
  94 + $sFullPath = $sRootFolder . '/';
  95 + $sFullPath .= $oFolder->getFullPath();
  96 +
  97 +
  98 + if (substr($sFullPath,-1) == '/') $sFullPath = substr($sFullPath,0,-1);
  99 + return $sFullPath;
  100 + }
  101 +
  102 +
79 103 /**
80 104 * Add a document to the zip file
81 105 */
... ... @@ -84,7 +108,7 @@ class ZipFolder {
84 108 $oFolder = Folder::get($oDocument->getFolderID());
85 109 }
86 110  
87   - $sDocPath = $oFolder->getFullPath().'/'.$oFolder->getName();
  111 + $sDocPath = $this->getFullFolderPath($oFolder);
88 112 $sDocName = $oDocument->getFileName();
89 113  
90 114 $sParentFolder = str_replace('<', '', str_replace('</', '', str_replace('>', '', sprintf('%s/%s', $this->sTmpPath, $sDocPath))));
... ... @@ -114,7 +138,7 @@ class ZipFolder {
114 138 * Add a folder to the zip file
115 139 */
116 140 function addFolderToZip($oFolder) {
117   - $sFolderPath = $oFolder->getFullPath().'/'.$oFolder->getName().'/';
  141 + $sFolderPath = $this->getFullFolderPath($oFolder) .'/';
118 142 $sParentFolder = str_replace('<', '', str_replace('</', '', str_replace('>', '', sprintf('%s/%s', $this->sTmpPath, $sFolderPath))));
119 143 $newDir = $this->sTmpPath;
120 144 $sFullPath = str_replace('<', '', str_replace('</', '', str_replace('>', '', $this->_convertEncoding($sFolderPath, true))));
... ...
lib/foldermanagement/folderutil.inc.php
... ... @@ -57,10 +57,10 @@ class KTFolderUtil {
57 57 }
58 58 $oStorage =& KTStorageManagerUtil::getSingleton();
59 59 $oFolder =& Folder::createFromArray(array(
60   - 'name' => ($sFolderName),
61   - 'description' => ($sFolderName),
62   - 'parentid' => $oParentFolder->getID(),
63   - 'creatorid' => $oUser->getID(),
  60 + 'name' => ($sFolderName),
  61 + 'description' => ($sFolderName),
  62 + 'parentid' => $oParentFolder->getID(),
  63 + 'creatorid' => $oUser->getID(),
64 64 ));
65 65 if (PEAR::isError($oFolder)) {
66 66 return $oFolder;
... ... @@ -100,12 +100,26 @@ class KTFolderUtil {
100 100 $oSubscriptionEvent = new SubscriptionEvent();
101 101 $oSubscriptionEvent->AddFolder($oFolder, $oParentFolder);
102 102  
103   - KTFolderUtil::updateSearchableText($oFolder);
104   -
105 103 return $oFolder;
106 104 }
107 105  
108 106 function move($oFolder, $oNewParentFolder, $oUser, $sReason=null) {
  107 + if ($oFolder->getId() == 1)
  108 + {
  109 + return PEAR::raiseError(_kt('Cannot move root folder!'));
  110 + }
  111 + if ($oFolder->getParentID() == $oNewParentFolder->getId())
  112 + {
  113 + // moved! done.
  114 + return;
  115 + }
  116 + $sFolderParentIds = $oFolder->getParentFolderIDs();
  117 + $sNewFolderParentIds = $oNewParentFolder->getParentFolderIDs();
  118 +
  119 + if (strpos($sNewFolderParentIds, "$sFolderParentIds,") === 0)
  120 + {
  121 + return PEAR::raiseError(_kt('Cannot move folder into a descendant folder!'));
  122 + }
109 123 if (KTFolderUtil::exists($oNewParentFolder, $oFolder->getName())) {
110 124 return PEAR::raiseError(_kt('Folder with the same name already exists in the new parent folder'));
111 125 }
... ... @@ -134,51 +148,42 @@ class KTFolderUtil {
134 148 $bChangePermissionObject = true;
135 149 }
136 150  
137   -
138 151 // First, deal with SQL, as it, at least, is guaranteed to be atomic
139 152 $table = 'folders';
140 153  
141   - if ($oNewParentFolder->getId() == 1) {
142   - $sNewParentFolderPath = $oNewParentFolder->getName();
143   - $sNewParentFolderIds = '';
144   - } else {
145   - $sNewParentFolderPath = sprintf("%s/%s", $oNewParentFolder->getFullPath(), $oNewParentFolder->getName());
146   - $sNewParentFolderIds = sprintf("%s,%s", $oNewParentFolder->getParentFolderIDs(), $oNewParentFolder->getID());
  154 + if ($oNewParentFolder->getId() == 1)
  155 + {
  156 + $sNewFullPath = $oFolder->getName();
  157 + $sNewParentFolderIds = "1";
147 158 }
148   -
149   - $sOldPath = $oFolder->getFullPath();
150   -
151   - if ($oNewParentFolder->getId() == 1) {
152   - } else {
153   - $sNewParentFolderPath = sprintf("%s/%s", $oNewParentFolder->getFullPath(), $oNewParentFolder->getName());
  159 + else
  160 + {
  161 + $sNewFullPath = $oNewParentFolder->getFullPath() . '/' . $oFolder->getName();
  162 + $sNewParentFolderIds = $oNewParentFolder->getParentFolderIDs() . ',' . $oNewParentFolder->getID();
154 163 }
155 164  
156 165 // Update the moved folder first...
157 166 $sQuery = "UPDATE $table SET full_path = ?, parent_folder_ids = ?, parent_id = ? WHERE id = ?";
158 167 $aParams = array(
159   - sprintf("%s", $sNewParentFolderPath),
160   - $sNewParentFolderIds,
161   - $oNewParentFolder->getID(),
162   - $oFolder->getID(),
  168 + $sNewFullPath,
  169 + $sNewParentFolderIds,
  170 + $oNewParentFolder->getID(),
  171 + $oFolder->getID(),
163 172 );
164 173 $res = DBUtil::runQuery(array($sQuery, $aParams));
165 174 if (PEAR::isError($res)) {
166 175 return $res;
167 176 }
168 177  
169   - if ($oFolder->getId() == 1) {
170   - $sOldFolderPath = $oFolder->getName();
171   - } else {
172   - $sOldFolderPath = sprintf("%s/%s", $oFolder->getFullPath(), $oFolder->getName());
173   - }
  178 + $sOldFolderPath = $oFolder->getFullPath();
174 179  
175 180 $sQuery = "UPDATE $table SET full_path = CONCAT(?, SUBSTRING(full_path FROM ?)), parent_folder_ids = CONCAT(?, SUBSTRING(parent_folder_ids FROM ?)) WHERE full_path LIKE ?";
176 181 $aParams = array(
177   - sprintf("%s", $sNewParentFolderPath),
178   - strlen($oFolder->getFullPath()) + 1,
179   - $sNewParentFolderIds,
180   - strlen($oFolder->getParentFolderIDs()) + 1,
181   - sprintf("%s%%", $sOldFolderPath),
  182 + $sNewFullPath,
  183 + strlen($oFolder->getFullPath()) + 1,
  184 + $sNewParentFolderIds,
  185 + strlen($oFolder->getParentFolderIDs()) + 1,
  186 + "$sOldFolderPath%"
182 187 );
183 188 $res = DBUtil::runQuery(array($sQuery, $aParams));
184 189 if (PEAR::isError($res)) {
... ... @@ -187,13 +192,7 @@ class KTFolderUtil {
187 192  
188 193 $table = 'documents';
189 194 $sQuery = "UPDATE $table SET full_path = CONCAT(?, SUBSTRING(full_path FROM ?)), parent_folder_ids = CONCAT(?, SUBSTRING(parent_folder_ids FROM ?)) WHERE full_path LIKE ?";
190   - $aParams = array(
191   - sprintf("%s", $sNewParentFolderPath),
192   - strlen($oFolder->getFullPath()) + 1,
193   - $sNewParentFolderIds,
194   - strlen($oFolder->getParentFolderIDs()) + 1,
195   - sprintf("%s%%", $sOldFolderPath),
196   - );
  195 + // use same $aParams as above
197 196 $res = DBUtil::runQuery(array($sQuery, $aParams));
198 197 if (PEAR::isError($res)) {
199 198 return $res;
... ... @@ -219,6 +218,7 @@ class KTFolderUtil {
219 218  
220 219 Document::clearAllCaches();
221 220 Folder::clearAllCaches();
  221 + $GLOBALS["_OBJECTCACHE"] = array();
222 222  
223 223 if ($bChangePermissionObject) {
224 224 $aOptions = array(
... ... @@ -236,21 +236,20 @@ class KTFolderUtil {
236 236 // First, deal with SQL, as it, at least, is guaranteed to be atomic
237 237 $table = "folders";
238 238  
239   - $sQuery = "UPDATE $table SET full_path = CONCAT(?, SUBSTRING(full_path FROM ?)) WHERE full_path LIKE ? OR full_path = ?";
240   -
241 239 if ($oFolder->getId() == 1) {
242 240 $sOldPath = $oFolder->getName();
243 241 $sNewPath = $sNewName;
244 242 } else {
245   - $sOldPath = sprintf("%s/%s", $oFolder->getFullPath(), $oFolder->getName());
246   - $sNewPath = sprintf("%s/%s", $oFolder->getFullPath(), $sNewName);
247   -
  243 + $sOldPath = $oFolder->getFullPath();
  244 + $sNewPath = dirname($oFolder->getFullPath()) . '/' . $sNewName;
248 245 }
  246 +
  247 + $sQuery = "UPDATE $table SET full_path = CONCAT(?, SUBSTRING(full_path FROM ?)) WHERE full_path LIKE ? OR full_path = ?";
249 248 $aParams = array(
250   - sprintf("%s", $sNewPath),
251   - strlen($sOldPath) + 1,
252   - $sOldPath.'/%',
253   - $sOldPath,
  249 + "$sNewPath/",
  250 + strlen($sOldPath) + 2,
  251 + $sOldPath.'/%',
  252 + $sOldPath,
254 253 );
255 254  
256 255 $res = DBUtil::runQuery(array($sQuery, $aParams));
... ... @@ -272,6 +271,7 @@ class KTFolderUtil {
272 271 }
273 272  
274 273 $oFolder->setName($sNewName);
  274 + $oFolder->setDescription($sNewName);
275 275 $res = $oFolder->update();
276 276  
277 277 $oTransaction = KTFolderTransaction::createFromArray(array(
... ... @@ -285,8 +285,6 @@ class KTFolderUtil {
285 285 return $oTransaction;
286 286 }
287 287  
288   - KTFolderUtil::updateSearchableText($oFolder);
289   -
290 288 Document::clearAllCaches();
291 289 Folder::clearAllCaches();
292 290  
... ... @@ -436,7 +434,8 @@ class KTFolderUtil {
436 434  
437 435 DBUtil::startTransaction();
438 436  
439   - while (!empty($aRemainingFolders) && $copyAll) {
  437 + while (!empty($aRemainingFolders) && $copyAll)
  438 + {
440 439 $iFolderId = array_pop($aRemainingFolders);
441 440 $oFolder = Folder::get($iFolderId);
442 441 if (PEAR::isError($oFolder) || ($oFolder == false)) {
... ... @@ -496,7 +495,7 @@ class KTFolderUtil {
496 495 $aRow['description'] = $sDestFolderName;
497 496 $aRow['parent_id'] = $oDestFolder->getId();
498 497 $aRow['parent_folder_ids'] = sprintf('%s,%s', $oDestFolder->getParentFolderIDs(), $oDestFolder->getId());
499   - $aRow['full_path'] = sprintf('%s/%s', $oDestFolder->getFullPath(), $oDestFolder->getName());
  498 + $aRow['full_path'] = $oDestFolder->getFullPath() . '/' . $aRow['name'];
500 499  
501 500 $id = DBUtil::autoInsert($sTable, $aRow);
502 501 if (PEAR::isError($id)) {
... ... @@ -530,7 +529,7 @@ class KTFolderUtil {
530 529 $sPrevParentId = $aRow['parent_id'];
531 530 $aRow['parent_id'] = $aFolderMap[$aRow['parent_id']]['parent_id'];
532 531 $aRow['parent_folder_ids'] = sprintf('%s,%s', $aFolderMap[$sPrevParentId]['parent_folder_ids'], $aRow['parent_id']);
533   - $aRow['full_path'] = sprintf('%s/%s', $aFolderMap[$sPrevParentId]['full_path'], $aFolderMap[$sPrevParentId]['name']);
  532 + $aRow['full_path'] = sprintf('%s/%s', $aFolderMap[$sPrevParentId]['full_path'], $aRow['name']);
534 533  
535 534 $id = DBUtil::autoInsert($sTable, $aRow);
536 535 if (PEAR::isError($id)) {
... ... @@ -573,35 +572,6 @@ class KTFolderUtil {
573 572  
574 573 return true;
575 574 }
576   -
577   - function updateSearchableText($oFolder) {
578   -
579   - // NEW SEARCH
580   -
581   - return;
582   -
583   - // very simple function to rebuild the searchable text for this
584   - // folder.
585   -
586   - // MyISAM table for fulltext index - no transactions.
587   -
588   - // get the folder text
589   - // XXX replace this with a trigger / producer set.
590   - $sSearchableText = $oFolder->getName();
591   -
592   - // do the update.
593   - $iFolderId = KTUtil::getId($oFolder);
594   - $sTable = KTUtil::getTableName('folder_searchable_text');
595   - $aDelete = array(
596   - "folder_id" => $iFolderId,
597   - );
598   - DBUtil::whereDelete($sTable, $aDelete);
599   - $aInsert = array(
600   - "folder_id" => $iFolderId,
601   - "folder_text" => $sSearchableText,
602   - );
603   - return DBUtil::autoInsert($sTable, $aInsert, array('noid' => true));
604   - }
605 575 }
606 576  
607 577 ?>
... ...
lib/upgrades/UpgradeFunctions.inc.php
... ... @@ -35,6 +35,8 @@
35 35 *
36 36 */
37 37  
  38 +//debugger_start_debug();
  39 +
38 40 require_once(KT_LIB_DIR . '/upgrades/Ini.inc.php');
39 41 require_once(KT_DIR . '/plugins/ktcore/scheduler/scheduler.php');
40 42 require_once(KT_LIB_DIR . '/database/schema.inc.php');
... ... @@ -57,7 +59,7 @@ class UpgradeFunctions {
57 59 '3.1.5' => array('upgradeSavedSearches'),
58 60 '3.1.6.3' => array('cleanupGroupMembership'),
59 61 '3.5.0' => array('cleanupOldKTAdminVersionNotifier', 'updateConfigFile35', 'registerIndexingTasks'),
60   - '3.5.2' => array('dropForeignKeys','dropPrimaryKeys','dropIndexes','createPrimaryKeys','createForeignKeys','createIndexes'),
  62 + '3.5.2' => array('setStorageEngine','dropForeignKeys','dropPrimaryKeys','dropIndexes','createPrimaryKeys','createForeignKeys','createIndexes', 'removeSlashesFromObjects'),
61 63 );
62 64  
63 65 var $descriptions = array(
... ... @@ -80,12 +82,14 @@ class UpgradeFunctions {
80 82 'cleanupOldKTAdminVersionNotifier' => 'Cleanup any old files from the old KTAdminVersionNotifier',
81 83 'updateConfigFile35' => 'Update the config.ini file for 3.5',
82 84 'registerIndexingTasks'=>'Register the required indexing background tasks',
  85 + 'setStorageEngine'=>'Recreate db integrity: Set storage engine to InnoDB for transaction safety',
83 86 'dropForeignKeys'=>'Recreate db integrity: Drop foreign keys on the database',
84 87 'dropPrimaryKeys'=>'Recreate db integrity:Drop primary keys on the database',
85 88 'dropIndexes'=>'Recreate db integrity:Drop indexes on the database',
86 89 'createPrimaryKeys'=>'Recreate db integrity:Create primary keys on the database',
87 90 'createForeignKeys'=>'Recreate db integrity:Create foreign keys on the database',
88   - 'createIndexes'=>'Recreate db integrity:Create indexes on the database'
  91 + 'createIndexes'=>'Recreate db integrity:Create indexes on the database',
  92 + 'removeSlashesFromObjects'=>'Remove slashes from documents and folders'
89 93 );
90 94 var $phases = array(
91 95 "setPermissionFolder" => 1,
... ... @@ -95,12 +99,13 @@ class UpgradeFunctions {
95 99 "fixUnits" => 1,
96 100 'applyDiscussionUpgrade' => -1,
97 101 'fixDocumentRoleAllocation' => -1,
98   - 'dropForeignKeys'=>1,
99   - 'dropPrimaryKeys'=>2,
100   - 'dropIndexes'=>3,
101   - 'createPrimaryKeys'=>4,
102   - 'createForeignKeys'=>5,
103   - 'createIndexes'=>6,
  102 + 'setStorageEngine'=>1,
  103 + 'dropForeignKeys'=>2,
  104 + 'dropPrimaryKeys'=>3,
  105 + 'dropIndexes'=>4,
  106 + 'createPrimaryKeys'=>5,
  107 + 'createForeignKeys'=>6,
  108 + 'createIndexes'=>7,
104 109 );
105 110  
106 111 function dropForeignKeys()
... ... @@ -139,6 +144,55 @@ class UpgradeFunctions {
139 144 $schemautil->createIndexes();
140 145 }
141 146  
  147 + // {{{ setStorageEngine
  148 + function setStorageEngine()
  149 + {
  150 + $schemautil = KTSchemaUtil::getSingleton();
  151 + $schemautil->setTablesToInnoDb();
  152 + }
  153 + // }}}
  154 +
  155 + function _removeSlashesFromFolders($folderid, $name, $full_path, $folder_ids)
  156 + {
  157 + $name = str_replace(array('/','\\'),array('-','-'), $name);
  158 +
  159 + // get folders
  160 + $sql = "select id, name from folders where parent_id=$folderid";
  161 + $ids = DBUtil::getResultArray($sql);
  162 +
  163 + // set to the latest values
  164 + $parent_ids = implode(',', $folder_ids);
  165 + if (empty($parent_ids)) $parent_ids = null;
  166 + if (empty($full_path)) $full_path = null;
  167 +
  168 + $full_path = (empty($full_path))?$name:($full_path . '/' . $name);
  169 + $folder_ids [] = $folderid;
  170 +
  171 + $sql = "update folders set name=?,description=?, full_path=?, parent_folder_ids=? where id=?";
  172 + DBUtil::runQuery(array($sql, array($name,$name, $full_path, $parent_ids, $folderid)));
  173 +
  174 + // update documents
  175 + $sql = "update documents set full_path=?, parent_folder_ids=? where folder_id=?";
  176 + DBUtil::runQuery(array($sql, array($full_path, $parent_ids, $folderid)));
  177 +
  178 +
  179 + // recurse subfolders
  180 + foreach($ids as $row)
  181 + {
  182 + $id = $row['id'];
  183 + $name = $row['name'];
  184 + UpgradeFunctions::_removeSlashesFromFolders($id, $name, $full_path, $folder_ids);
  185 + }
  186 + }
  187 +
  188 + function removeSlashesFromObjects()
  189 + {
  190 + $GLOBALS["_OBJECTCACHE"] = array();
  191 +
  192 + UpgradeFunctions::_removeSlashesFromFolders(1, '', array(), array());
  193 + DBUtil::commit();
  194 + }
  195 +
142 196  
143 197 // {{{ _setPermissionFolder
144 198 function _setPermissionFolder($iFolderId) {
... ...
plugins/ktcore/KTWidgets.php
1 1 <?php
2 2 /**
3 3 * $Id$
4   - *
  4 + *
5 5 * KnowledgeTree Open Source Edition
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
8   - *
  8 + *
9 9 * This program is free software; you can redistribute it and/or modify it under
10 10 * the terms of the GNU General Public License version 3 as published by the
11 11 * Free Software Foundation.
12   - *
  12 + *
13 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 16 * details.
17   - *
  17 + *
18 18 * You should have received a copy of the GNU General Public License
19 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20   - *
  20 + *
21 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23   - *
  23 + *
24 24 * The interactive user interfaces in modified source and object code versions
25 25 * of this program must display Appropriate Legal Notices, as required under
26 26 * Section 5 of the GNU General Public License version 3.
27   - *
  27 + *
28 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 29 * these Appropriate Legal Notices must retain the display of the "Powered by
30   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  30 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
31 31 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
32   - * must display the words "Powered by KnowledgeTree" and retain the original
33   - * copyright notice.
  32 + * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * copyright notice.
34 34 * Contributor( s): ______________________________________
35 35 */
36 36  
... ... @@ -51,24 +51,24 @@ class KTCoreHiddenWidget extends KTWidget {
51 51 class KTCoreFileWidget extends KTWidget {
52 52 var $sNamespace = 'ktcore.widgets.file';
53 53 var $sTemplate = 'ktcore/forms/widgets/file';
54   -
  54 +
55 55 function wrapName($outer) {
56 56 $this->sName = sprintf('_kt_attempt_unique_%s', $this->sName);
57 57 // we don't have access via "wrap" when processing, so we can't actually
58 58 // wrap. just don't use a lot of names
59 59 }
60   -
  60 +
61 61 function process($data){
62 62 $tname = sprintf('_kt_attempt_unique_%s', $this->sName);
63 63 return array($this->sBasename => $_FILES[$tname]);
64 64 }
65   -
  65 +
66 66 function getValidators() {
67 67 if (!$this->bAutoValidate) {
68 68 return null;
69 69 }
70   -
71   - $oVF =& KTValidatorFactory::getSingleton();
  70 +
  71 + $oVF =& KTValidatorFactory::getSingleton();
72 72 return $oVF->get('ktcore.validators.requiredfile', array(
73 73 'test' => sprintf('_kt_attempt_unique_%s', $this->sName),
74 74 'basename' => $this->sBasename,
... ... @@ -85,27 +85,27 @@ class KTCoreTextWidget extends KTWidget {
85 85 class KTCoreReasonWidget extends KTWidget {
86 86 var $sNamespace = 'ktcore.widgets.reason';
87 87 var $sTemplate = 'ktcore/forms/widgets/text';
88   -
  88 +
89 89 function configure($aOptions) {
90 90 $res = parent::configure($aOptions);
91 91 if (PEAR::isError($res)) {
92 92 return $res;
93 93 }
94   -
  94 +
95 95 // FIXME make required *either* per-action property
96 96 // FIXME or a global pref.
97 97 $global_required_default = true;
98 98 $this->bRequired = KTUtil::arrayGet($aOptions, 'required', $global_required_default, false);
99   -
  99 +
100 100 $this->aOptions['cols'] = KTUtil::arrayGet($aOptions, 'cols', 60);
101   - $this->aOptions['rows'] = KTUtil::arrayGet($aOptions, 'rows', 3);
  101 + $this->aOptions['rows'] = KTUtil::arrayGet($aOptions, 'rows', 3);
102 102 }
103 103 }
104 104  
105 105 class KTCoreBooleanWidget extends KTWidget {
106 106 var $sNamespace = 'ktcore.widgets.boolean';
107 107 var $sTemplate = 'ktcore/forms/widgets/boolean';
108   -
  108 +
109 109 function setDefault($mValue) {
110 110 $this->value = ($mValue == true);
111 111 }
... ... @@ -114,20 +114,20 @@ class KTCoreBooleanWidget extends KTWidget {
114 114 class KTCorePasswordWidget extends KTWidget {
115 115 var $sNamespace = 'ktcore.widgets.password';
116 116 var $sTemplate = 'ktcore/forms/widgets/password';
117   -
  117 +
118 118 var $bConfirm = false;
119 119 var $sConfirmDescription;
120   -
  120 +
121 121 function configure($aOptions) {
122 122 $res = parent::configure($aOptions);
123 123 if (PEAR::isError($res)) {
124 124 return $res;
125 125 }
126   -
  126 +
127 127 $this->bConfirm = KTUtil::arrayGet($aOptions, 'confirm', false);
128 128 $this->sConfirmDescription = KTUtil::arrayGet($aOptions, 'confirm_description');
129 129 }
130   -
  130 +
131 131 function process($raw_data) {
132 132 // since we're essentially a string, pass *that* out as the primary
133 133 // but we also might want to confirm, and if so we use a private name
... ... @@ -135,7 +135,7 @@ class KTCorePasswordWidget extends KTWidget {
135 135 if ($this->bConfirm) {
136 136 $res['_password_confirm_' . $this->sBasename] = array(
137 137 'base' => $raw_data[$this->sBasename]['base'],
138   - 'confirm' => $raw_data[$this->sBasename]['confirm'],
  138 + 'confirm' => $raw_data[$this->sBasename]['confirm'],
139 139 );
140 140 $res[$this->sBasename] = $raw_data[$this->sBasename]['base'];
141 141 } else {
... ... @@ -143,10 +143,10 @@ class KTCorePasswordWidget extends KTWidget {
143 143 }
144 144 return $res;
145 145 }
146   -
  146 +
147 147 function getValidators() {
148 148 if (!$this->bAutoValidate) {
149   - return null;
  149 + return null;
150 150 }
151 151 $oVF =& KTValidatorFactory::getSingleton();
152 152  
... ... @@ -156,7 +156,7 @@ class KTCorePasswordWidget extends KTWidget {
156 156 'test' => $this->sOrigname,
157 157 'basename' => $this->sBasename
158 158 ));
159   -
  159 +
160 160 return $val;
161 161 }
162 162 }
... ... @@ -164,53 +164,53 @@ class KTCorePasswordWidget extends KTWidget {
164 164  
165 165 class KTCoreSelectionWidget extends KTWidget {
166 166 var $sNamespace = 'ktcore.widgets.selection';
167   -
  167 +
168 168 var $bMulti = false; // multiselection
169 169 var $USE_SIMPLE = 10; // point at which to switch to a dropdown/multiselect
170 170 var $bUseSimple; // only use checkboxes, regardless of size
171   -
  171 +
172 172 var $aVocab;
173   -
  173 +
174 174 var $sEmptyMessage;
175   -
  175 +
176 176 var $_valuesearch;
177   -
  177 +
178 178 function configure($aOptions) {
179 179 $res = parent::configure($aOptions);
180 180 if (PEAR::isError($res)) {
181 181 return $res;
182 182 }
183   -
  183 +
184 184 $this->bUseSimple = KTUtil::arrayGet($aOptions, 'simple_select', null, false);
185 185 $this->bMulti = KTUtil::arrayGet($aOptions, 'multi', false);
186   -
  186 +
187 187 $this->aVocab = (array) KTUtil::arrayGet($aOptions, 'vocab');
188   - $this->sEmptyMessage = KTUtil::arrayGet($aOptions, 'empty_message',
  188 + $this->sEmptyMessage = KTUtil::arrayGet($aOptions, 'empty_message',
189 189 _kt('No options available for this field.'));
190 190 }
191   -
  191 +
192 192 function getWidget() {
193 193 // very simple, general purpose passthrough. Chances are this is sufficient,
194 194 // just override the template being used.
195   - $bHasErrors = false;
  195 + $bHasErrors = false;
196 196 if (count($this->aErrors) != 0) { $bHasErrors = true; }
197 197  
198   - // at this last moment we pick the template to use
  198 + // at this last moment we pick the template to use
199 199 $total = count($this->aVocab);
200 200 if ($this->bUseSimple === true) {
201   - $this->sTemplate = 'ktcore/forms/widgets/simple_selection';
  201 + $this->sTemplate = 'ktcore/forms/widgets/simple_selection';
202 202 } else if ($this->bUseSimple === false) {
203   - $this->sTemplate = 'ktcore/forms/widgets/selection';
  203 + $this->sTemplate = 'ktcore/forms/widgets/selection';
204 204 } else if (is_null($this->bUseSimple) && ($total <= $this->USE_SIMPLE)) {
205 205 $this->sTemplate = 'ktcore/forms/widgets/simple_selection';
206 206 } else {
207 207 $this->sTemplate = 'ktcore/forms/widgets/selection';
208 208 }
209   -
210   - $oTemplating =& KTTemplating::getSingleton();
  209 +
  210 + $oTemplating =& KTTemplating::getSingleton();
211 211 $oTemplate = $oTemplating->loadTemplate($this->sTemplate);
212 212  
213   - // have to do this here, and not in "configure" since it breaks
  213 + // have to do this here, and not in "configure" since it breaks
214 214 // entity-select.
215 215 $unselected = KTUtil::arrayGet($this->aOptions, 'unselected_label');
216 216 if (!empty($unselected)) {
... ... @@ -222,7 +222,7 @@ class KTCoreSelectionWidget extends KTWidget {
222 222 foreach ($this->aVocab as $k => $v) {
223 223 $vocab[$k] = $v;
224 224 }
225   -
  225 +
226 226 $this->aVocab = $vocab;
227 227  
228 228 // make sure its the selected one if there's no value specified.
... ... @@ -239,7 +239,7 @@ class KTCoreSelectionWidget extends KTWidget {
239 239 $this->_valuesearch[$v] = true;
240 240 }
241 241 }
242   -
  242 +
243 243 $aTemplateData = array(
244 244 'context' => $this,
245 245 'name' => $this->sName,
... ... @@ -252,7 +252,7 @@ class KTCoreSelectionWidget extends KTWidget {
252 252 );
253 253 return $oTemplate->render($aTemplateData);
254 254 }
255   -
  255 +
256 256 function selected($lookup) {
257 257 if ($this->bMulti) {
258 258 return $this->_valuesearch[$lookup];
... ... @@ -260,38 +260,38 @@ class KTCoreSelectionWidget extends KTWidget {
260 260 return ($this->value == $lookup);
261 261 }
262 262 }
263   -
  263 +
264 264 function process($raw_data) {
265 265 return array($this->sBasename => $raw_data[$this->sBasename]);
266   - }
  266 + }
267 267 }
268 268  
269 269 // this happens so often, its worth creating a util function for it
270 270 class KTCoreEntitySelectionWidget extends KTCoreSelectionWidget {
271 271 var $sNamespace = 'ktcore.widgets.entityselection';
272   -
  272 +
273 273 var $sIdMethod;
274 274 var $sLabelMethod;
275   -
  275 +
276 276 function configure($aOptions) {
277 277 $res = parent::configure($aOptions);
278   - if (PEAR::isError($res)) {
  278 + if (PEAR::isError($res)) {
279 279 return $res;
280 280 }
281   -
  281 +
282 282 // the selection widget's configure method has already setup almost
283   - // all the vars we need. we have one utility here, where you pass
  283 + // all the vars we need. we have one utility here, where you pass
284 284 // in a list of existing entities that match the query, and we work
285 285 // from there.
286   -
  286 +
287 287 $this->sIdMethod = KTUtil::arrayGet($aOptions, 'id_method', 'getId');
288 288 $this->sLabelMethod = KTUtil::arrayGet($aOptions, 'label_method');
289 289 if (empty($this->sLabelMethod)) {
290 290 return PEAR::raiseError(_kt('No label method specified.'));
291 291 }
292 292 $existing_entities = (array) KTUtil::arrayGet($aOptions, 'existing_entities');
293   -
294   - // now we construct the "value" array from this set
  293 +
  294 + // now we construct the "value" array from this set
295 295 // BUT ONLY IF WE DON'T HAVE A "VALUE" array.
296 296 if (empty($this->value)) {
297 297 $this->value = array();
... ... @@ -299,7 +299,7 @@ class KTCoreEntitySelectionWidget extends KTCoreSelectionWidget {
299 299 $this->value[] = call_user_func(array(&$oEntity, $this->sIdMethod));
300 300 }
301 301 }
302   -
  302 +
303 303 // we next walk the "vocab" array, constructing a new one based on the
304 304 // functions passed in so far.
305 305 $new_vocab = array();
... ... @@ -316,7 +316,7 @@ class KTCoreEntitySelectionWidget extends KTCoreSelectionWidget {
316 316 class KTDescriptorSelectionWidget extends KTWidget {
317 317 var $sNamespace = 'ktcore.widgets.descriptorselection';
318 318 var $sTemplate = 'ktcore/forms/widgets/descriptor';
319   -
  319 +
320 320 var $aJavascript = array('resources/js/jsonlookup.js');
321 321  
322 322 function configure($aOptions) {
... ... @@ -324,24 +324,24 @@ class KTDescriptorSelectionWidget extends KTWidget {
324 324 if (PEAR::isError($res)) {
325 325 return $res;
326 326 }
327   -
328   -
  327 +
  328 +
329 329 }
330   -
  330 +
331 331 function getWidget() {
332   - $oTemplating =& KTTemplating::getSingleton();
333   - $oTemplate = $oTemplating->loadTemplate($this->sTemplate);
  332 + $oTemplating =& KTTemplating::getSingleton();
  333 + $oTemplate = $oTemplating->loadTemplate($this->sTemplate);
334 334  
335 335 $src_location = $this->aOptions['src'];
336 336 $sJS = sprintf('addLoadEvent(initJSONLookup("%s", "%s"));', $this->sBasename, $src_location);
337 337  
338 338  
339 339 // its bad, but that's life.
340   - $oPage =& $GLOBALS['main'];
341   - $oPage->requireJSStandalone($sJS);
342   -
  340 + $oPage =& $GLOBALS['main'];
  341 + $oPage->requireJSStandalone($sJS);
  342 +
343 343 $this->aOptions['multi'] = true;
344   -
  344 +
345 345 $aTemplateData = array(
346 346 'context' => $this,
347 347 'label' => $this->sLabel,
... ... @@ -357,7 +357,7 @@ class KTDescriptorSelectionWidget extends KTWidget {
357 357 'short_name' => $this->sBasename,
358 358 'options' => $this->aOptions,
359 359 );
360   - return $oTemplate->render($aTemplateData);
  360 + return $oTemplate->render($aTemplateData);
361 361 }
362 362 }
363 363  
... ... @@ -365,7 +365,7 @@ class KTCoreTreeMetadataWidget extends KTWidget {
365 365 var $sNamespace = 'ktcore.widgets.treemetadata';
366 366 var $iFieldId;
367 367 var $aCSS = array('resources/css/kt-treewidget.css');
368   -
  368 +
369 369 function configure($aOptions) {
370 370 $res = parent::configure($aOptions);
371 371 if (PEAR::isError($res)) {
... ... @@ -377,19 +377,19 @@ class KTCoreTreeMetadataWidget extends KTWidget {
377 377 return PEAR::raiseError(_kt('Tree metadata fields must be associated with a particular type.'));
378 378 }
379 379 }
380   -
  380 +
381 381 function getWidget() {
382 382 // very simple, general purpose passthrough. Chances are this is sufficient,
383 383 // just override the template being used.
384   - $bHasErrors = false;
385   -
  384 + $bHasErrors = false;
  385 +
386 386 require_once(KT_LIB_DIR . '/documentmanagement/MDTree.inc');
387   -
  387 +
388 388 $fieldTree = new MDTree();
389 389 $fieldTree->buildForField($this->iFieldId);
390 390 $fieldTree->setActiveItem($this->value);
391   - return $fieldTree->_evilTreeRenderer($fieldTree, $this->sName);
392   - }
  391 + return $fieldTree->_evilTreeRenderer($fieldTree, $this->sName);
  392 + }
393 393 }
394 394  
395 395 // wrap a set of fields into a core, basic one.
... ... @@ -406,16 +406,16 @@ class KTCoreFieldsetWidget extends KTWidget {
406 406 function configure($aOptions) {
407 407 // do NOT use parent.
408 408 $this->sLabel = KTUtil::arrayGet($aOptions, 'label');
409   - $this->sDescription = KTUtil::arrayGet($aOptions, 'description');
  409 + $this->sDescription = KTUtil::arrayGet($aOptions, 'description');
410 410 $this->sName = KTUtil::arrayGet($aOptions, 'name');
411   - $this->sBasename = $this->sName;
412   -
  411 + $this->sBasename = $this->sName;
  412 +
413 413 $aWidgets = (array) KTUtil::arrayGet($aOptions, 'widgets');
414 414 // very similar to the one in forms.inc.php
415 415 if (is_null($this->_oWF)) {
416 416 $this->_oWF =& KTWidgetFactory::getSingleton();
417 417 }
418   -
  418 +
419 419 $this->_widgets = array();
420 420 // we don't want to expose the factory stuff to the user - its an
421 421 // arbitrary distinction to the user. Good point from NBM ;)
... ... @@ -428,24 +428,24 @@ class KTCoreFieldsetWidget extends KTWidget {
428 428 } else {
429 429 $namespaceOrObject = $aInfo[0];
430 430 $config = (array) $aInfo[1];
431   -
  431 +
432 432 $this->_widgets[] = $this->_oWF->get($namespaceOrObject, $config);
433 433 }
434   - }
  434 + }
435 435  
436 436 }
437 437  
438 438 function render() {
439   - $oTemplating =& KTTemplating::getSingleton();
  439 + $oTemplating =& KTTemplating::getSingleton();
440 440 $oTemplate = $oTemplating->loadTemplate('ktcore/forms/widgets/fieldset');
441   -
  441 +
442 442 $aTemplateData = array(
443 443 'context' => $this,
444 444 'label' => $this->sLabel,
445 445 'description' => $this->sDescription,
446 446 'widgets' => $this->renderWidgets(),
447 447 );
448   - return $oTemplate->render($aTemplateData);
  448 + return $oTemplate->render($aTemplateData);
449 449 }
450 450  
451 451 function renderWidgets() {
... ... @@ -458,11 +458,11 @@ class KTCoreFieldsetWidget extends KTWidget {
458 458 $rendered[] = $v->render();
459 459 }
460 460 }
461   -
  461 +
462 462 return implode(' ', $rendered);
463 463 }
464 464  
465   - function getDefault() {
  465 + function getDefault() {
466 466 // we need to do a little more admin here
467 467 // to obtain the default
468 468 // annoyingly
... ... @@ -475,7 +475,7 @@ class KTCoreFieldsetWidget extends KTWidget {
475 475 }
476 476 return $d;
477 477 }
478   -
  478 +
479 479 function setDefault($aValue) {
480 480 $d = (array) $aValue;
481 481 foreach ($this->_widgets as $k => $w) {
... ... @@ -483,8 +483,8 @@ class KTCoreFieldsetWidget extends KTWidget {
483 483 $oWidget->setDefault(KTUtil::arrayGet($d, $oWidget->getBasename(), $oWidget->getDefault()));
484 484 }
485 485 }
486   -
487   - function wrapName($sOuter) {
  486 +
  487 + function wrapName($sOuter) {
488 488 $this->sName = sprintf('%s[%s]', $sOuter, $this->sBasename);
489 489 // now, chain to our children
490 490 foreach ($this->_widgets as $k => $v) {
... ... @@ -495,12 +495,12 @@ class KTCoreFieldsetWidget extends KTWidget {
495 495 $oWidget->wrapName($this->sName);
496 496 }
497 497 }
498   -
  498 +
499 499 function setErrors($aErrors = null) {
500 500 if (is_array($aErrors)) {
501 501 $this->aErrors = $aErrors;
502 502 }
503   -
  503 +
504 504 foreach ($this->_widgets as $k => $w) {
505 505 $oWidget =& $this->_widgets[$k];
506 506 $oWidget->setErrors(KTUtil::arrayGet($aErrors, $oWidget->getBasename()));
... ... @@ -511,10 +511,10 @@ class KTCoreFieldsetWidget extends KTWidget {
511 511 function getValidators() {
512 512 // we use a fieldsetValidator here.
513 513 $extra_validators = array();
514   -
  514 +
515 515 foreach ($this->_widgets as $oWidget) {
516 516 $res = $oWidget->getValidators();
517   -
  517 +
518 518 if (!is_null($res)) {
519 519 if (is_array($res)) {
520 520 $extra_validators = kt_array_merge($extra_validators, $res);
... ... @@ -523,23 +523,23 @@ class KTCoreFieldsetWidget extends KTWidget {
523 523 }
524 524 }
525 525 }
526   -
527   - $oVF =& KTValidatorFactory::getSingleton();
  526 +
  527 + $oVF =& KTValidatorFactory::getSingleton();
528 528 return array($oVF->get('ktcore.validators.fieldset', array(
529   - 'test' => $this->sBasename,
  529 + 'test' => $this->sBasename,
530 530 'validators' => &$extra_validators,
531 531 )));
532 532 }
533   -
  533 +
534 534 function process($raw_data) {
535 535 $d = (array) KTUtil::arrayGet($raw_data, $this->sBasename);
536 536 $o = array();
537   -
  537 +
538 538 // we now need to recombine the process
539 539 foreach ($this->_widgets as $oWidget) {
540 540 $o =& kt_array_merge($o, $oWidget->process($d));
541 541 }
542   -
  542 +
543 543 return array($this->sBasename => $o);
544 544 }
545 545  
... ... @@ -547,49 +547,49 @@ class KTCoreFieldsetWidget extends KTWidget {
547 547  
548 548 class KTCoreTransparentFieldsetWidget extends KTCoreFieldsetWidget {
549 549 var $sNamespace = 'ktcore.widgets.transparentfieldset';
550   -
  550 +
551 551 function render() {
552   - $oTemplating =& KTTemplating::getSingleton();
  552 + $oTemplating =& KTTemplating::getSingleton();
553 553 $oTemplate = $oTemplating->loadTemplate('ktcore/forms/widgets/transparent_fieldset');
554   -
  554 +
555 555 $aTemplateData = array(
556 556 'widgets' => $this->renderWidgets(),
557 557 );
558   - return $oTemplate->render($aTemplateData);
559   - }
  558 + return $oTemplate->render($aTemplateData);
  559 + }
560 560 }
561 561  
562 562  
563 563  
564 564 class KTExtraConditionalFieldsetWidget extends KTCoreFieldsetWidget {
565 565 var $sNamespace = 'ktextra.conditionalmetadata.fieldset';
566   -
  566 +
567 567 function render() {
568   - $oTemplating =& KTTemplating::getSingleton();
  568 + $oTemplating =& KTTemplating::getSingleton();
569 569 $oTemplate = $oTemplating->loadTemplate('ktcore/forms/widgets/conditionalfieldset');
570   -
  570 +
571 571 $aTemplateData = array(
572 572 'context' => $this,
573 573 'label' => $this->sLabel,
574   - 'description' => $this->sDescription,
  574 + 'description' => $this->sDescription,
575 575 );
576   - return $oTemplate->render($aTemplateData);
577   - }
  576 + return $oTemplate->render($aTemplateData);
  577 + }
578 578 }
579 579  
580 580  
581 581 class KTCoreCollectionWidget extends KTWidget {
582 582 var $sNamespace = 'ktcore.widgets.collection';
583 583 var $sTemplate = 'ktcore/forms/widgets/collectionframe';
584   -
  584 +
585 585 var $oCollection;
586 586 var $sCode;
587 587  
588 588 function configure($aOptions) {
589 589 $aOptions['broken_name'] = KTUtil::arrayGet($aOptions, 'broken_name', true, false);
590   -
  590 +
591 591 $res = parent::configure($aOptions);
592   - if (PEAR::isError($res)) {
  592 + if (PEAR::isError($res)) {
593 593 return $res;
594 594 }
595 595  
... ... @@ -600,19 +600,19 @@ class KTCoreCollectionWidget extends KTWidget {
600 600 if(empty($this->iFolderId)) return PEAR::raiseError(_kt('No initial folder specified specified.'));
601 601  
602 602 $this->aBCUrlParams = KTUtil::arrayGet($aOptions, 'bcurl_params', array());
603   -
  603 +
604 604 $this->aCols = array();
605 605 foreach($this->oCollection->columns as $oCol) {
606 606 $this->aCols[] = $oCol->namespace;
607   - }
  607 + }
608 608  
609 609 $this->sCode = KTUtil::randomString();
610 610 $this->sCollection = serialize($this->oCollection);
611 611 $_SESSION['collection_widgets'][$this->sCode] = serialize($this);
612 612  
613 613 $this->requireJSResource('resources/js/collectionframe.js');
614   -
615   -
  614 +
  615 +
616 616 }
617 617  
618 618 function getTargetURL() {
... ... @@ -620,13 +620,13 @@ class KTCoreCollectionWidget extends KTWidget {
620 620 $oPlugin =& $oPluginRegistry->getPlugin('ktcore.plugin');
621 621 $sPath = $oPlugin->getPagePath('collection');
622 622 $oKTConfig =& KTConfig::getSingleton();
623   -
  623 +
624 624 $sName = $this->sName;
625 625 if (KTUtil::arrayGet($this->aOptions, 'broken_name', false)) {
626 626 $this->sName = 'fFolderId';
627 627 }
628   -
629   - $sPath = KTUtil::addQueryString($sPath, array('code'=>$this->sCode,
  628 +
  629 + $sPath = KTUtil::addQueryString($sPath, array('code'=>$this->sCode,
630 630 'fFolderId'=>$this->iFolderId,
631 631 'varname' => $sName));
632 632  
... ... @@ -636,8 +636,8 @@ class KTCoreCollectionWidget extends KTWidget {
636 636 function getCollection() {
637 637 $oCR =& KTColumnRegistry::getSingleton();
638 638 //print '<pre>';
639   - foreach($this->aCols as $ns) {
640   -
  639 + foreach($this->aCols as $ns) {
  640 +
641 641 $oCR->getColumn($ns);
642 642 }
643 643 $this->oCollection = unserialize($this->sCollection);
... ... @@ -671,25 +671,25 @@ class KTCoreFolderCollectionWidget extends KTCoreCollectionWidget {
671 671 $collection->setQueryObject($qObj);
672 672  
673 673 $aO = $collection->getEnvironOptions();
674   - $collection->setOptions($aO);
675   -
  674 + $collection->setOptions($aO);
  675 +
676 676 $aOptions['collection'] = $collection;
677   - $aOptions['broken_name'] = $false;
678   -
  677 + $aOptions['broken_name'] = $false;
  678 +
679 679 return parent::configure($aOptions);
680 680 }
681   -
  681 +
682 682 function getDefault() { return $this->value; }
683   - function setDefault($mValue) {
  683 + function setDefault($mValue) {
684 684 if ($mValue != $this->value) {
685 685 $this->oCollection->setQueryObject(new FolderBrowseQuery($mValue));
686 686 $this->value = $mValue;
687 687 $this->aOptions['folder_id'] = $this->value;
688 688 $this->iFolderId = $this->value;
689 689 $this->sCollection = serialize($this->oCollection);
690   - $_SESSION['collection_widgets'][$this->sCode] = serialize($this);
  690 + $_SESSION['collection_widgets'][$this->sCode] = serialize($this);
691 691 }
692   - }
  692 + }
693 693 }
694 694  
695 695 class KTCoreCollectionPage extends KTStandardDispatcher {
... ... @@ -699,30 +699,33 @@ class KTCoreCollectionPage extends KTStandardDispatcher {
699 699 $folder_path_names = $oFolder->getPathArray();
700 700 $folder_path_ids = explode(',', $oFolder->getParentFolderIds());
701 701 $folder_path_ids[] = $oFolder->getId();
702   - if ($folder_path_ids[0] == 0) {
703   - array_shift($folder_path_ids);
704   - array_shift($folder_path_names);
  702 +
  703 + if (!empty($folder_path_ids) && empty($folder_path_ids[0]))
  704 + {
  705 + array_shift($folder_path_ids);
705 706 }
706 707  
707   -
  708 + $oRoot = Folder::get(1);
  709 + $folder_path_names = array_merge(array($oRoot->getName()), $folder_path_names);
  710 +
708 711  
709 712 foreach (range(0, count($folder_path_ids) - 1) as $index) {
710 713 $id = $folder_path_ids[$index];
711   -
  714 +
712 715 $aParams = kt_array_merge($aURLParams, array('fFolderId'=>$id, 'code'=>$sCode, 'varname'=>$sName));
713 716 $url = KTUtil::addQueryString($_SERVER['PHP_SELF'], $aParams);
714 717 $aBreadcrumbs[] = array('url' => $url, 'name' => $folder_path_names[$index]);
715 718 }
716   -
  719 +
717 720 return $aBreadcrumbs;
718   - }
719   -
  721 + }
  722 +
720 723  
721 724  
722 725 function do_main() {
723 726  
724 727 $sCode = KTUtil::arrayGet($_REQUEST, 'code');
725   - $sName = KTUtil::arrayGet($_REQUEST, 'varname','fFolderId');
  728 + $sName = KTUtil::arrayGet($_REQUEST, 'varname','fFolderId');
726 729 $oWidget = unserialize($_SESSION['collection_widgets'][$sCode]);
727 730  
728 731 $oCollection = $oWidget->getCollection();
... ... @@ -735,17 +738,17 @@ class KTCoreCollectionPage extends KTStandardDispatcher {
735 738  
736 739 $aOptions = array('ignorepermissions' => KTBrowseUtil::inAdminMode($this->oUser, $oFolder));
737 740 $oCollection->_queryObj->folder_id = $oFolder->getId();
738   -
  741 +
739 742 $aOptions = $oCollection->getEnvironOptions();
740 743 $aOptions['return_url'] = KTUtil::addQueryString($_SERVER['PHP_SELF'], array('code'=>$sCode, 'varname' => $sName, 'fFolderId' => $oFolder->getId()));
741   -
  744 +
742 745 $oCollection->setOptions($aOptions);
743   -
  746 +
744 747 // add the collection code to the title column QS params
745   -
746   - foreach($oWidget->aCols as $ns) {
  748 +
  749 + foreach($oWidget->aCols as $ns) {
747 750 $aColOpts = $oCollection->getColumnOptions($ns);
748   - $aColOpts['qs_params'] = kt_array_merge(KTUtil::arrayGet($aColOpts, 'qs_params', array()),
  751 + $aColOpts['qs_params'] = kt_array_merge(KTUtil::arrayGet($aColOpts, 'qs_params', array()),
749 752 array('code' => $sCode, 'varname' => $sName));
750 753 $oCollection->setColumnOptions($ns, $aColOpts);
751 754 }
... ... @@ -753,7 +756,7 @@ class KTCoreCollectionPage extends KTStandardDispatcher {
753 756 // make the breadcrumbs
754 757 $aBreadcrumbs = $this->_generate_breadcrumbs($oFolder, $sCode, $oWidget->aBCUrlParams, $sName);
755 758  
756   - print KTTemplating::renderTemplate('ktcore/forms/widgets/collection',
  759 + print KTTemplating::renderTemplate('ktcore/forms/widgets/collection',
757 760 array(
758 761 'collection'=> $oCollection,
759 762 'folder' => $oFolder,
... ... @@ -780,33 +783,33 @@ class KTCoreConditionalSelectionWidget extends KTCoreSelectionWidget {
780 783  
781 784 var $bIsMaster;
782 785 var $bMappings;
783   -
  786 +
784 787 function _getFieldIdForMetadataId($iMetadata) {
785 788 $sTable = 'metadata_lookup';
786 789 $sQuery = "SELECT document_field_id FROM " . $sTable . " WHERE id = ?";
787 790 $aParams = array($iMetadata);
788   -
  791 +
789 792 $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'document_field_id');
790 793 if (PEAR::isError($res)) {
791 794 return false;
792 795 }
793 796 return $res;
794 797 }
795   -
  798 +
796 799  
797 800 function configure($aOptions) {
798 801 $res = parent::configure($aOptions);
799   - if (PEAR::isError($res)) {
  802 + if (PEAR::isError($res)) {
800 803 return $res;
801 804 }
802   -
  805 +
803 806 $this->sIdMethod = KTUtil::arrayGet($aOptions, 'id_method', 'getId');
804 807 $this->sLabelMethod = KTUtil::arrayGet($aOptions, 'label_method');
805 808 if (empty($this->sLabelMethod)) {
806 809 return PEAR::raiseError(_kt('No label method specified.'));
807 810 }
808 811 $existing_entities = (array) KTUtil::arrayGet($aOptions, 'existing_entities');
809   -
  812 +
810 813 if (empty($this->value)) {
811 814 $this->value = array();
812 815 foreach ($existing_entities as $oEntity) {
... ... @@ -829,7 +832,7 @@ class KTCoreConditionalSelectionWidget extends KTCoreSelectionWidget {
829 832  
830 833 foreach($oFieldset->getFields() as $oField) {
831 834 $c = array();
832   -
  835 +
833 836 foreach($oField->getEnabledValues() as $oMetadata) {
834 837 $a = array();
835 838 // print '<pre>';
... ... @@ -838,7 +841,7 @@ class KTCoreConditionalSelectionWidget extends KTCoreSelectionWidget {
838 841 if($nvals) {
839 842 foreach($nvals as $i=>$aVals) {
840 843 $a = array_merge($a, $aVals);
841   -
  844 +
842 845 foreach($aVals as $id) {
843 846 $field = $this->_getFieldIdForMetadataId($id);
844 847 // print 'id ' . $id . ' is in field ' . $field . "<br/>";
... ... @@ -853,14 +856,14 @@ class KTCoreConditionalSelectionWidget extends KTCoreSelectionWidget {
853 856 }
854 857 $aConnections[$oField->getId()] = $c;
855 858 }
856   -
  859 +
857 860 //exit(0);
858 861  
859 862 $oJSON = new Services_JSON;
860 863 $this->sLookupsJSON = $oJSON->encode($aLookups);
861 864 $this->sConnectionsJSON = $oJSON->encode($aConnections);
862 865 }
863   -
  866 +
864 867  
865 868 $new_vocab = array();
866 869 foreach ($this->aVocab as $oEntity) {
... ... @@ -872,12 +875,12 @@ class KTCoreConditionalSelectionWidget extends KTCoreSelectionWidget {
872 875 }
873 876  
874 877 function getWidget() {
875   - $bHasErrors = false;
  878 + $bHasErrors = false;
876 879 if (count($this->aErrors) != 0) { $bHasErrors = true; }
877 880  
878   - $this->sTemplate = 'ktcore/forms/widgets/conditional_selection';
879   -
880   - $oTemplating =& KTTemplating::getSingleton();
  881 + $this->sTemplate = 'ktcore/forms/widgets/conditional_selection';
  882 +
  883 + $oTemplating =& KTTemplating::getSingleton();
881 884 $oTemplate = $oTemplating->loadTemplate($this->sTemplate);
882 885  
883 886 $unselected = KTUtil::arrayGet($this->aOptions, 'unselected_label');
... ... @@ -900,7 +903,7 @@ class KTCoreConditionalSelectionWidget extends KTCoreSelectionWidget {
900 903 $this->_valuesearch[$v] = true;
901 904 }
902 905 }
903   -
  906 +
904 907 $aTemplateData = array(
905 908 'context' => $this,
906 909 'name' => $this->sName,
... ... @@ -918,7 +921,7 @@ class KTCoreConditionalSelectionWidget extends KTCoreSelectionWidget {
918 921 );
919 922 return $oTemplate->render($aTemplateData);
920 923 }
921   -
  924 +
922 925  
923 926  
924 927 }
... ...
search2/indexing/indexerCore.inc.php
... ... @@ -179,8 +179,7 @@ class QueryResultItem
179 179 }
180 180 else
181 181 {
182   - $this->fullpath = $result['full_path'] . '/' . $result['name'];
183   - if (substr($this->fullpath,0,1) == '/') $this->fullpath = substr($this->fullpath,1);
  182 + $this->fullpath = $result['full_path'];
184 183 }
185 184  
186 185 $this->mimeType = $result['mimetype'];
... ...
search2/search/fields/FullPathField.inc.php 0 → 100644
  1 +<?php
  2 +
  3 +/**
  4 + * $Id:$
  5 + *
  6 + * KnowledgeTree Open Source Edition
  7 + * Document Management Made Simple
  8 + * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
  9 + *
  10 + * This program is free software; you can redistribute it and/or modify it under
  11 + * the terms of the GNU General Public License version 3 as published by the
  12 + * Free Software Foundation.
  13 + *
  14 + * This program is distributed in the hope that it will be useful, but WITHOUT
  15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17 + * details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + *
  22 + * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
  23 + * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
  24 + *
  25 + * The interactive user interfaces in modified source and object code versions
  26 + * of this program must display Appropriate Legal Notices, as required under
  27 + * Section 5 of the GNU General Public License version 3.
  28 + *
  29 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  30 + * these Appropriate Legal Notices must retain the display of the "Powered by
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * copyright notice.
  35 + * Contributor( s): ______________________________________
  36 + *
  37 + */
  38 +
  39 +class FullPathField extends DBFieldExpr
  40 +{
  41 + public $general_op = ExprOp::CONTAINS;
  42 +
  43 + public function __construct()
  44 + {
  45 + parent::__construct('full_path', 'documents', _kt('Full Path'));
  46 + $this->setAlias('Full Path');
  47 + }
  48 +
  49 + public function getInputRequirements()
  50 + {
  51 + return array('value'=>array('type'=>FieldInputType::TEXT));
  52 + }
  53 +
  54 + public function is_valid()
  55 + {
  56 + return DefaultOpCollection::validateParent($this, DefaultOpCollection::$contains);
  57 + }
  58 +}
  59 +
  60 +?>
0 61 \ No newline at end of file
... ...