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