Commit 362a287d5c00c2fb1962495a22c3b2e557c8138b

Authored by kevin_fourie
1 parent 7441bdf5

Merged in from STABLE trunk..

KTS-3234
"CLONE -When a document starts of as e.g. a .doc file, but the next version is a pdf file, then it remains to be seen as a Word document in some respects(SUP-675)"
Fixed. The mime type is only changed if the filename changes and is derived from the new filename.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen

Plus various updates that did not make the last commit.

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/branches/3.5.3a-Release-Branch@9259 c91229c3-7414-0410-bfa2-8a42b809f60b
browse.php
... ... @@ -176,16 +176,6 @@ class BrowseDispatcher extends KTStandardDispatcher {
176 176 $portlet = new KTActionPortlet(sprintf(_kt('Actions on this folder')));
177 177 $aActions = KTFolderActionUtil::getFolderActionsForFolder($oFolder, $this->oUser);
178 178 $portlet->setActions($aActions,null);
179   - // Set upload button
180   - $btnName = _kt('Add Document');
181   - $btnAction = '';
182   - foreach ($aActions as $item){
183   - if($item->getDisplayName() == $btnName){
184   - $btnAction = array($item);
185   - break;
186   - }
187   - }
188   - $portlet->setButton($btnAction, 'folder_upload');
189 179 $this->oPage->addPortlet($portlet);
190 180  
191 181  
... ...
lib/actions/documentaction.inc.php
... ... @@ -6,31 +6,31 @@
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2008 KnowledgeTree Inc.
8 8 * Portions copyright The Jam Warehouse Software (Pty) Limited
9   - *
  9 + *
10 10 * This program is free software; you can redistribute it and/or modify it under
11 11 * the terms of the GNU General Public License version 3 as published by the
12 12 * Free Software Foundation.
13   - *
  13 + *
14 14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 17 * details.
18   - *
  18 + *
19 19 * You should have received a copy of the GNU General Public License
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
22   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23 23 * California 94120-7775, or email info@knowledgetree.com.
24   - *
  24 + *
25 25 * The interactive user interfaces in modified source and object code versions
26 26 * of this program must display Appropriate Legal Notices, as required under
27 27 * Section 5 of the GNU General Public License version 3.
28   - *
  28 + *
29 29 * In accordance with Section 7(b) of the GNU General Public License version 3,
30 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
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32 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
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
34 34 * copyright notice.
35 35 * Contributor( s): ______________________________________
36 36 *
... ... @@ -155,17 +155,21 @@ class KTDocumentAction extends KTStandardDispatcher {
155 155 }
156 156  
157 157 function getName() {
158   - return sanitizeForSQLtoHTML($this->sName);
  158 + return $this->sName;
159 159 }
160 160  
161 161 function getDisplayName() {
162 162 // Should be overridden by the i18nised display name
163 163 // This is here solely for backwards compatibility
164   - return sanitizeForSQLtoHTML($this->sDisplayName);
  164 + return $this->sDisplayName;
165 165 }
166 166  
167 167 function getDescription() {
168   - return sanitizeForSQLtoHTML($this->sDescription);
  168 + return $this->sDescription;
  169 + }
  170 +
  171 + function getButton(){
  172 + return false;
169 173 }
170 174  
171 175 function customiseInfo($aInfo) {
... ... @@ -192,8 +196,8 @@ class KTDocumentAction extends KTStandardDispatcher {
192 196 $actions = KTDocumentActionUtil::getDocumentActionsForDocument($this->oDocument, $this->oUser);
193 197 $oPortlet = new KTActionPortlet(sprintf(_kt('Document actions')));
194 198 $oPortlet->setActions($actions, $this->sName);
195   - $this->oPage->addPortlet($oPortlet);
196 199  
  200 + $this->oPage->addPortlet($oPortlet);
197 201 $this->oPage->setSecondaryTitle($this->oDocument->getName());
198 202  
199 203 return true;
... ...
lib/actions/folderaction.inc.php
... ... @@ -132,6 +132,10 @@ class KTFolderAction extends KTStandardDispatcher {
132 132 return sanitizeForSQLtoHTML($this->sDescription);
133 133 }
134 134  
  135 + function getButton(){
  136 + return false;
  137 + }
  138 +
135 139 function customiseInfo($aInfo) {
136 140 return $aInfo;
137 141 }
... ... @@ -157,16 +161,6 @@ class KTFolderAction extends KTStandardDispatcher {
157 161 $portlet = new KTActionPortlet(sprintf(_kt('Actions on this folder')));
158 162 $aActions = KTFolderActionUtil::getFolderActionsForFolder($this->oFolder, $this->oUser);
159 163 $portlet->setActions($aActions,$this->sName);
160   - // Set upload button
161   - $btnName = _kt('Add Document');
162   - $btnAction = '';
163   - foreach ($aActions as $item){
164   - if($item->getDisplayName() == $btnName){
165   - $btnAction = array($item);
166   - break;
167   - }
168   - }
169   - $portlet->setButton($btnAction, 'folder_upload');
170 164 $this->oPage->addPortlet($portlet);
171 165  
172 166 if (KTPermissionUtil::userHasPermissionOnItem($this->oUser, 'ktcore.permissions.folder_details', $this->oFolder)) {
... ...
lib/documentmanagement/documentutil.inc.php
... ... @@ -65,9 +65,6 @@ class KTDocumentUtil {
65 65 function checkin($oDocument, $sFilename, $sCheckInComment, $oUser, $aOptions = false) {
66 66 $oStorage =& KTStorageManagerUtil::getSingleton();
67 67  
68   - $sType = KTMime::getMimeTypeFromFile($sFilename);
69   - $iMimeTypeId = KTMime::getMimeTypeID($sType, $sFilename);
70   -
71 68 $iFileSize = filesize($sFilename);
72 69  
73 70 $iPreviousMetadataVersion = $oDocument->getMetadataVersionId();
... ... @@ -103,19 +100,19 @@ class KTDocumentUtil {
103 100 }
104 101 $oDocument->setFileSize($iFileSize);
105 102  
106   - $sFilename = $oDocument->getFileName();
107   -
108 103 if(is_array($aOptions)) {
109 104 $sFilename = KTUtil::arrayGet($aOptions, 'newfilename', '');
110   - if(strlen($sFilename)) {
111   - global $default;
112   - $oDocument->setFileName($sFilename);
113   - $default->log->info('renamed document ' . $oDocument->getId() . ' to ' . $sFilename);
  105 + if(!empty($sFilename)) {
  106 + global $default;
  107 + $oDocument->setFileName($sFilename);
  108 + $default->log->info('renamed document ' . $oDocument->getId() . ' to ' . $sFilename);
  109 +
  110 + // If the filename has changed then update the mime type
  111 + $iMimeTypeId = KTMime::getMimeTypeID('', $sFilename);
  112 + $oDocument->setMimeTypeId($iMimeTypeId);
114 113 }
115 114 }
116 115  
117   - $oDocument->setMimeTypeId($iMimeTypeId);
118   -
119 116 $bSuccess = $oDocument->update();
120 117 if ($bSuccess !== true) {
121 118 if (PEAR::isError($bSuccess)) {
... ... @@ -1524,4 +1521,4 @@ class KTUploadNewFile {
1524 1521 }
1525 1522 }
1526 1523  
1527 1524 -?>
  1525 +?>
1528 1526 \ No newline at end of file
... ...
lib/widgets/portlet.inc.php
... ... @@ -116,7 +116,7 @@ class KTActionPortlet extends KTPortlet {
116 116 var $actions = array();
117 117  
118 118 var $bActive = true;
119   - var $btn = '';
  119 + var $btns = '';
120 120  
121 121 // current action is the one we are currently on.
122 122 function setActions($actions, $currentaction) {
... ... @@ -128,86 +128,77 @@ class KTActionPortlet extends KTPortlet {
128 128 unset($aInfo["url"]);
129 129 $aInfo['active'] = true;
130 130 }
131   - $this->actions[$aInfo['name']] = $aInfo;
  131 + $aBtn = $action->getButton();
  132 +
  133 + if($aBtn){
  134 + $this->btns[$aInfo['name']] = array_merge($aInfo, $aBtn);
  135 + }else{
  136 + $this->actions[$aInfo['name']] = $aInfo;
  137 + }
132 138 }
133 139 }
134 140 ksort($this->actions);
  141 + ksort($this->btns);
135 142 }
136 143  
137 144 /**
138   - * Display a button for a given action
  145 + * Render a button for a given action
139 146 *
140   - * @param array $action
141   - * @param string $btn
142   - * @return boolean
  147 + * @param string $text
  148 + * @param string $link
  149 + * @param string $class
  150 + * @return unknown
143 151 */
144   - function setButton($action, $btn) {
145   - // Ensure action is set
146   - if(!isset($action[0])){
147   - return false;
148   - }
149   -
150   - $info = $action[0]->getInfo();
151   -
152   - // Ensure user has permission on / access to the action
153   - if(empty($info)){
154   - return false;
155   - }
156   -
157   - $link = $info['url'];
158   - $text = $info['name'];
159   -
160   - switch($btn){
161   - case 'document_checkin':
162   - $text = _kt('Checkin Document');
163   - $class = 'arrow_upload';
164   - break;
165   - case 'folder_upload':
166   - $text = _kt('Upload Document');
167   - $class = 'arrow_upload';
168   - break;
169   - case 'document_download':
170   - $text = _kt('Download Document');
171   - $class = 'arrow_download';
172   - break;
173   - default:
174   - return false;
175   - }
  152 + function renderBtn($text, $link, $class) {
176 153  
177 154 // Create button html
178 155 $button = "<div class='portlet_button'>
179 156 <a href='$link'>
180 157 <div class='big_btn_left'></div>
181 158 <div class='big_btn_middle'>
182   - <div class='btn_text'>{$text}
183   - </div>
184   - <div class='{$class}'>
185   - </div>
  159 + <div class='btn_text'>{$text}</div>
  160 + <div class='{$class}'></div>
186 161 </div>
187 162 <div class='big_btn_right'></div>
188 163 </a>
189 164 </div>";
190 165  
191   - $this->btn = $button;
192   - return true;
  166 + return $button;
  167 + }
  168 +
  169 + /**
  170 + * Render the specified actions as buttons
  171 + */
  172 + function showButtons() {
  173 + if(empty($this->btns)){
  174 + return '';
  175 + }
  176 +
  177 + $rendered = '';
  178 + foreach ($this->btns as $btn){
  179 + $text = !empty($btn['display_text']) ? $btn['display_text'] : $btn['name'];
  180 + $link = $btn['url'];
  181 + $class = $btn['arrow_class'];
  182 + $rendered .= $this->renderBtn($text, $link, $class);
  183 + }
  184 +
  185 + return $rendered;
193 186 }
194 187  
195 188 function render() {
196 189 if (empty($this->actions)) {
197 190 return null;
198 191 }
  192 +
  193 + $btn = $this->showButtons();
  194 +
199 195 $oTemplating =& KTTemplating::getSingleton();
200 196 $oTemplate = $oTemplating->loadTemplate('kt3/portlets/actions_portlet');
201 197 $aTemplateData = array(
202 198 'context' => $this,
  199 + 'btn' => $btn
203 200 );
204 201  
205   - // Display a button above the action list
206   - if(isset($this->btn) && !empty($this->btn)){
207   - $aTemplateData['showBtn'] = true;
208   - $aTemplateData['btn'] = $this->btn;
209   - }
210   -
211 202 return $oTemplate->render($aTemplateData);
212 203 }
213 204 }
... ...
plugins/ktcore/KTDocumentActions.php
... ... @@ -6,31 +6,31 @@
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2008 KnowledgeTree Inc.
8 8 * Portions copyright The Jam Warehouse Software (Pty) Limited
9   - *
  9 + *
10 10 * This program is free software; you can redistribute it and/or modify it under
11 11 * the terms of the GNU General Public License version 3 as published by the
12 12 * Free Software Foundation.
13   - *
  13 + *
14 14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 17 * details.
18   - *
  18 + *
19 19 * You should have received a copy of the GNU General Public License
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
22   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23 23 * California 94120-7775, or email info@knowledgetree.com.
24   - *
  24 + *
25 25 * The interactive user interfaces in modified source and object code versions
26 26 * of this program must display Appropriate Legal Notices, as required under
27 27 * Section 5 of the GNU General Public License version 3.
28   - *
  28 + *
29 29 * In accordance with Section 7(b) of the GNU General Public License version 3,
30 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
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32 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
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
34 34 * copyright notice.
35 35 * Contributor( s): ______________________________________
36 36 *
... ... @@ -326,6 +326,13 @@ class KTDocumentViewAction extends KTDocumentAction {
326 326 return _kt('Download');
327 327 }
328 328  
  329 + function getButton() {
  330 + $btn = array();
  331 + $btn['display_text'] = _kt('Download Document');
  332 + $btn['arrow_class'] = 'arrow_download';
  333 + return $btn;
  334 + }
  335 +
329 336 function customiseInfo($aInfo) {
330 337 $aInfo['alert'] = _kt('This will download a copy of the document and is not the same as Checking Out a document. Changes to this downloaded file will not be managed in the DMS.');
331 338 return $aInfo;
... ... @@ -531,6 +538,13 @@ class KTDocumentCheckInAction extends KTDocumentAction {
531 538 return _kt('Checkin');
532 539 }
533 540  
  541 + function getButton() {
  542 + $btn = array();
  543 + $btn['display_text'] = _kt('Check Document In');
  544 + $btn['arrow_class'] = 'arrow_upload';
  545 + return $btn;
  546 + }
  547 +
534 548 function getInfo() {
535 549 if (!$this->oDocument->getIsCheckedOut()) {
536 550 return null;
... ... @@ -853,8 +867,8 @@ class KTDocumentDeleteAction extends KTDocumentAction {
853 867 $_SESSION['KTErrorMessage'][]= _kt('This document can\'t be deleted because it is checked out');
854 868 controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
855 869 exit(0);
856   - }
857   -
  870 + }
  871 +
858 872 return true;
859 873 }
860 874  
... ... @@ -869,11 +883,11 @@ class KTDocumentDeleteAction extends KTDocumentAction {
869 883 'submit_label' => _kt('Delete Document'),
870 884 'context' => &$this,
871 885 ));
872   -
  886 +
873 887  
874 888 return $oForm;
875 889 }
876   -
  890 +
877 891 function form_main() {
878 892 $oForm = new KTForm;
879 893 $oForm->setOptions(array(
... ... @@ -916,7 +930,7 @@ class KTDocumentDeleteAction extends KTDocumentAction {
916 930 ));
917 931 return $oTemplate->render();
918 932 }
919   -
  933 +
920 934 function do_confirm(){
921 935 $this->oPage->setBreadcrumbDetails(_kt('Confirm delete'));
922 936 $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/delete_confirm');
... ... @@ -1386,11 +1400,11 @@ class KTDocumentArchiveAction extends KTDocumentAction {
1386 1400 'submit_label' => _kt('Archive Document'),
1387 1401 'context' => &$this,
1388 1402 ));
1389   -
  1403 +
1390 1404  
1391 1405 return $oForm;
1392 1406 }
1393   -
  1407 +
1394 1408 function form_main() {
1395 1409 $oForm = new KTForm;
1396 1410 $oForm->setOptions(array(
... ... @@ -1435,7 +1449,7 @@ class KTDocumentArchiveAction extends KTDocumentAction {
1435 1449 ));
1436 1450 return $oTemplate->render();
1437 1451 }
1438   -
  1452 +
1439 1453 function do_confirm(){
1440 1454 $this->oPage->setBreadcrumbDetails(_kt('Confirm archive'));
1441 1455 $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/archive_confirm');
... ...
templates/kt3/portlets/actions_portlet.smarty
1   -{if $showBtn}
  1 +{if $btn}
2 2 <div style='width: 100%;'>{$btn}</div>
3 3 {/if}
4 4 <ul class="actionlist">
... ...
view.php
... ... @@ -96,18 +96,6 @@ class ViewDocumentDispatcher extends KTStandardDispatcher {
96 96 $this->actions = KTDocumentActionUtil::getDocumentActionsForDocument($this->oDocument, $this->oUser);
97 97 $oPortlet = new KTActionPortlet(sprintf(_kt('Document actions'), $this->oDocument->getName()));
98 98 $oPortlet->setActions($this->actions, $currentaction);
99   -
100   - // Set download / checkin button
101   - if($this->oDocument->getIsCheckedOut() && $this->oDocument->getCheckedOutUserID() == $this->oUser->getId()){
102   - $btn = 'document_checkin';
103   - $aNames = array('ktcore.actions.document.checkin');
104   - $btnAction = KTDocumentActionUtil::getDocumentActionsByNames($aNames, 'documentaction', $this->oDocument, $this->oUser);
105   - }else {
106   - $btn = 'document_download';
107   - $aNames = array('ktcore.actions.document.view');
108   - $btnAction = KTDocumentActionUtil::getDocumentActionsByNames($aNames, 'documentinfo', $this->oDocument, $this->oUser);
109   - }
110   - $oPortlet->setButton($btnAction, $btn);
111 99 $this->oPage->addPortlet($oPortlet);
112 100 }
113 101  
... ...