Commit 263aeba9e936a619f5f900420fdb3777c3165c0a

Authored by Brad Shuttleworth
1 parent e3b539cb

- missed a dc fix.

- Fixed password issue
- This adds states to discussion threads.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4620 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/discussions/DiscussionThread.inc
... ... @@ -32,6 +32,9 @@ class DiscussionThread extends KTEntity{
32 32 var $iLastCommentId = -1;
33 33 var $iNumberOfViews = 0;
34 34 var $iNumberOfReplies = 0;
  35 + var $iState = 0;
  36 + var $iCloseMetadataVersion = 0;
  37 + var $sCloseReason = "";
35 38 var $iCreatorId;
36 39  
37 40 var $_aFieldToSelect = array(
... ... @@ -41,6 +44,9 @@ class DiscussionThread extends KTEntity{
41 44 'iLastCommentId' => 'last_comment_id',
42 45 'iNumberOfViews' => 'views',
43 46 'iNumberOfReplies' => 'replies',
  47 + 'iState' => 'state',
  48 + 'iCloseMetadataVersion' => 'close_metadata_version',
  49 + 'sCloseReason' => 'close_reason',
44 50 'iCreatorId' => 'creator_id',
45 51 );
46 52  
... ... @@ -71,7 +77,14 @@ class DiscussionThread extends KTEntity{
71 77 function getNumberOfReplies(){ return $this->iNumberOfReplies; }
72 78 function incrementNumberOfReplies(){ $this->iNumberOfReplies += 1; }
73 79 function setNumberOfReplies($iValue){ $this->iNumberOfReplies = $iValue; }
74   -
  80 + function getState(){ return $this->iState; }
  81 + function setState($iValue){ $this->iState = $iValue; }
  82 + function getCloseMetadataVersion(){ return $this->iCloseMetadataVersion; }
  83 + function setCloseMetadataVersion($iValue){ $this->iCloseMetadataVersion = $iValue; }
  84 + function getCloseReason(){ return $this->sCloseReason; }
  85 + function setCloseReason($sValue){ $this->sCloseReason = $sValue; }
  86 +
  87 +
75 88 /**
76 89 * Get a All commentId's seperated by a comma ","
77 90 */
... ...
plugins/ktcore/folder/addDocument.php
... ... @@ -49,7 +49,7 @@ class KTFolderAddDocumentAction extends KTFolderAction {
49 49 $aVocab[$oDocumentType->getId()] = $oDocumentType->getName();
50 50 }
51 51 $fieldOptions = array("vocab" => $aVocab);
52   - $add_fields[] = new KTLookupWidget(_('Document Type'), 'FIXME', 'fDocumentTypeId', null, $this->oPage, true, "add-document-type", $fieldErrors, $fieldOptions);
  52 + $add_fields[] = new KTLookupWidget(_('Document Type'), _('Document Types, defined by the administrator, are used to categorise documents. Please select a Document Type from the list below.'), 'fDocumentTypeId', null, $this->oPage, true, "add-document-type", $fieldErrors, $fieldOptions);
53 53  
54 54 $fieldsets = array();
55 55 $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton();
... ...
plugins/ktstandard/KTDiscussion.php
... ... @@ -40,12 +40,13 @@ class KTDiscussionThreadListRenderer {
40 40 }
41 41  
42 42 class KTCommentListRenderer {
43   - function render($context, $oComment) {
  43 + function render($context, $oComment, $oThread) {
44 44 $this->oComment = $oComment;
45 45 $oTemplate = $context->oValidator->validateTemplate('ktstandard/action/discussion_comment_list_item');
46 46 $oCreator = User::get($oComment->getUserId());
47 47 $oTemplate->setData(array(
48 48 'comment' => $oComment,
  49 + 'state' => $oThread->getState(),
49 50 'creator' => $oCreator,
50 51 'context' => $context,
51 52 ));
... ... @@ -138,17 +139,29 @@ class KTDocumentDiscussionAction extends KTDocumentAction {
138 139 );
139 140 $this->oPage->setBreadcrumbDetails(_("viewing comments"));
140 141 $oTemplate =& $this->oValidator->validateTemplate('ktstandard/action/discussion_thread');
  142 +
141 143 // Fields for new thread creation
142   - $fields = array();
143   - $fields[] = new KTStringWidget(_("Subject"), _("The topic of discussion in this thread"), "subject", "", $this->oPage, true);
144   - $fields[] = new KTTextWidget(_("Body"), _("Your contribution to the discussion in this thread"), "body", "", $this->oPage, true, null, null, array("cols" => 50, "rows" => 10));
  144 + $replyFields = array();
  145 + $replyFields[] = new KTStringWidget(_("Subject"), _("The topic of discussion in this thread"), "subject", "", $this->oPage, true);
  146 + $replyFields[] = new KTTextWidget(_("Body"), _("Your contribution to the discussion in this thread"), "body", "", $this->oPage, true, null, null, array("cols" => 50, "rows" => 10));
  147 +
  148 + // Fields for closing thread (if user has write permission)
  149 + $closeFields = array();
  150 +
  151 + $oPermission =& KTPermission::getByName('ktcore.permissions.write');
  152 + if (PEAR::isError($oPermission) ||
  153 + KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oDocument)) {
  154 + $closeFields[] = new KTTextWidget(_("Reason"), _("Describe the reason for closing this thread"), "reason", "", $this->oPage, true, null, null, array("cols" => 50, "rows" => 5));
  155 + }
145 156  
146 157 $aTemplateData = array(
147 158 'context' => &$this,
148   - 'fields' => $fields,
  159 + 'replyfields' => $replyFields,
  160 + 'closefields' => $closeFields,
149 161 'thread' => $oThread,
150 162 'commentrenderer' => new KTCommentListRenderer(),
151 163 );
  164 +
152 165 return $oTemplate->render($aTemplateData);
153 166 }
154 167  
... ... @@ -197,4 +210,50 @@ class KTDocumentDiscussionAction extends KTDocumentAction {
197 210 $this->successRedirectTo('viewThread', _("Reply posted"), sprintf('fDocumentId=%d&fThreadId=%d', $this->oDocument->getId(), $oThread->getId()));
198 211 exit(0);
199 212 }
  213 +
  214 + function do_closethread() {
  215 + $aErrorOptions = array(
  216 + 'redirect_to' => array('main', sprintf('fDocumentId=%d', $this->oDocument->getId())),
  217 + );
  218 +
  219 + $iThreadId = KTUtil::arrayGet($_REQUEST, 'fThreadId');
  220 + $oThread = DiscussionThread::get($iThreadId);
  221 +
  222 + $this->oValidator->notError($oThread, $aErrorOptions);
  223 +
  224 + $aErrorOptions = array(
  225 + 'redirect_to' => array('viewthread', sprintf('fDocumentId=%d&fThreadId=%d', $this->oDocument->getId(), $oThread->getId())),
  226 + );
  227 +
  228 + $oPermission =& KTPermission::getByName('ktcore.permissions.write');
  229 +
  230 + if (PEAR::isError($oPermission)) {
  231 + $this->errorRedirectTo(implode('&', $aErrorOptions['redirect_to']), _("Error getting permission"));
  232 + }
  233 + if (!KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oDocument)) {
  234 + $this->errorRedirectTo(implode('&', $aErrorOptions['redirect_to']), _("You do not have permission to close this thread"));
  235 + }
  236 +
  237 + $aErrorOptions['message'] = _("No reason provided");
  238 + $sReason = KTUtil::arrayGet($_REQUEST, 'reason');
  239 + $sReason = $this->oValidator->validateString($sReason, $aErrorOptions);
  240 +
  241 + // Start the transaction comment creation
  242 + $this->startTransaction();
  243 +
  244 + $oThread->setState(1);
  245 + $oThread->setCloseMetadataVersion($this->oDocument->getMetadataVersion());
  246 + $oThread->setCloseReason($sReason);
  247 + $res = $oThread->update();
  248 +
  249 + $aErrorOptions['message'] = _("There was an error updating the thread with the new comment");
  250 + $this->oValidator->notError($res, $aErrorOptions);
  251 +
  252 + // Thread closed correctly, so commit
  253 + $this->commitTransaction();
  254 +
  255 + $this->successRedirectTo('viewThread', _("Thread closed"), sprintf('fDocumentId=%d&fThreadId=%d', $this->oDocument->getId(), $oThread->getId()));
  256 + exit(0);
  257 + }
  258 +
200 259 }
... ...
preferences.php
... ... @@ -75,9 +75,9 @@ class PreferencesDispatcher extends KTStandardDispatcher {
75 75 $confirm_password = KTUtil::arrayGet($_REQUEST, 'confirm_password');
76 76  
77 77 if (empty($password)) {
78   - $this->errorRedirect("setPassword", _("You must specify a password."));
  78 + $this->errorRedirectTo("setPassword", _("You must specify a password."));
79 79 } else if ($password !== $confirm_password) {
80   - $this->errorRedirect("setPassword", _("The passwords you specified do not match."));
  80 + $this->errorRedirectTo("setPassword", _("The passwords you specified do not match."));
81 81 }
82 82  
83 83 $KTConfig =& KTConfig::getSingleton();
... ...
sql/mysql/install/structure.sql
... ... @@ -190,6 +190,9 @@ CREATE TABLE `discussion_threads` (
190 190 `last_comment_id` int(11) NOT NULL default '0',
191 191 `views` int(11) NOT NULL default '0',
192 192 `replies` int(11) NOT NULL default '0',
  193 + `state` int(1) NOT NULL default '0',
  194 + `close_metadata_version` int(11) NOT NULL default '0',
  195 + `close_reason` text NOT NULL default '',
193 196 `creator_id` int(11) NOT NULL default '0',
194 197 UNIQUE KEY `id` (`id`)
195 198 ) TYPE=InnoDB ;
... ... @@ -431,7 +434,7 @@ CREATE TABLE `documents` (
431 434 `description` varchar(200) NOT NULL default '',
432 435 `security` int(11) NOT NULL default '0',
433 436 `mime_id` int(11) NOT NULL default '0',
434   - `folder_id` int(11) NOT NULL default '0',
  437 + `folder_id` int(11) default '1',
435 438 `major_version` int(11) NOT NULL default '0',
436 439 `minor_version` int(11) NOT NULL default '0',
437 440 `is_checked_out` tinyint(1) NOT NULL default '0',
... ... @@ -841,6 +844,18 @@ CREATE TABLE `organisations_lookup` (
841 844  
842 845 -- --------------------------------------------------------
843 846  
  847 +CREATE TABLE `plugins` (
  848 + `id` int(11) NOT NULL default '0',
  849 + `namespace` varchar(255) NOT NULL default '',
  850 + `path` varchar(255) NOT NULL default '',
  851 + `version` int(11) NOT NULL default '0',
  852 + `disabled` tinyint(1) NOT NULL default '0',
  853 + `data` text,
  854 + PRIMARY KEY (`id`),
  855 + KEY `name` (`namespace`)
  856 +) ENGINE=InnoDB;
  857 +
  858 +
844 859 --
845 860 -- Table structure for table `permission_assignments`
846 861 --
... ... @@ -2135,6 +2150,15 @@ CREATE TABLE `zseq_workflows` (
2135 2150 PRIMARY KEY (`id`)
2136 2151 ) TYPE=MyISAM ;
2137 2152  
  2153 +
  2154 +CREATE TABLE `zseq_plugins` (
  2155 + `id` int(10) unsigned NOT NULL auto_increment,
  2156 + PRIMARY KEY (`id`)
  2157 +) ENGINE=MyISAM;
  2158 +
  2159 +
  2160 +
  2161 +
2138 2162 --
2139 2163 -- Constraints for dumped tables
2140 2164 --
... ...
templates/ktstandard/action/discussion.smarty
... ... @@ -8,6 +8,7 @@
8 8 <th>{i18n}Views{/i18n}</th>
9 9 <th>{i18n}Replies{/i18n}</th>
10 10 <th>{i18n}Last activity{/i18n}</th>
  11 + <th>{i18n}State{/i18n}</th>
11 12 </tr>
12 13 </thead>
13 14 <tbody>
... ...
templates/ktstandard/action/discussion_comment_list_item.smarty
... ... @@ -25,4 +25,7 @@ dl.kt-discussion-comment &gt; dt {
25 25 <dd>{$comment->getBody()}</dd>
26 26 </dl>
27 27  
  28 +{if not $state}
28 29 <a class="kt-discussion-post-link" href="#kt-discussion-post">{i18n}Post a reply{/i18n}</a>
  30 +{/if}
  31 +
... ...
templates/ktstandard/action/discussion_thread.smarty
1 1 {foreach from=$thread->getCommentsSortedByDate() item=oComment}
2   - {$commentrenderer->render($context, $oComment)}
  2 + {$commentrenderer->render($context, $oComment, $thread)}
3 3 {/foreach}
4 4  
  5 +{if not $thread->getState()}
5 6 <form method="POST" action="{$smarty.server.PHP_SELF}">
6 7 <input type="hidden" name="action" value="postreply" />
7 8 <input type="hidden" name="fDocumentId" value="{$context->oDocument->getId()}" />
8 9 <input type="hidden" name="fThreadId" value="{$thread->getId()}" />
9 10 <fieldset><legend>{i18n}Post a reply{/i18n}</legend>
10 11 <a name="kt-discussion-post"></a>
11   -{foreach from=$fields item=oWidget}
  12 +{foreach from=$replyfields item=oWidget}
12 13 {$oWidget->render()}
13 14 {/foreach}
14 15  
... ... @@ -17,3 +18,31 @@
17 18 </div>
18 19 </fieldset>
19 20 </form>
  21 +
  22 +
  23 +{if $closefields}
  24 +
  25 +<form method="POST" action="{$smarty.server.PHP_SELF}">
  26 +<input type="hidden" name="action" value="closethread" />
  27 +<input type="hidden" name="fDocumentId" value="{$context->oDocument->getId()}" />
  28 +<input type="hidden" name="fThreadId" value="{$thread->getId()}" />
  29 +<fieldset><legend>{i18n}Close this thread{/i18n}</legend>
  30 +{foreach from=$closefields item=oWidget}
  31 + {$oWidget->render()}
  32 +{/foreach}
  33 +
  34 +<div class="form_actions ">
  35 + <input type="submit" name="submit" value="{i18n}Close this thread{/i18n}" />
  36 +</div>
  37 +</fieldset>
  38 +</form>
  39 +
  40 +{/if}
  41 +
  42 +{else}
  43 +
  44 +<div>
  45 + Thread closed ({$thread->getCloseReason()})
  46 +</div>
  47 +
  48 +{/if}
... ...
templates/ktstandard/action/discussion_thread_list_item.smarty
... ... @@ -4,4 +4,5 @@
4 4 <td>{$thread->getNumberOfViews()}</td>
5 5 <td>{$thread->getNumberOfReplies()}</td>
6 6 <td>{$last_comment->getDate()}</td>
  7 + <td>{if $thread->getState()}Closed at metadata version {$thread->getCloseMetadataVersion()}{else}Open{/if}</td>
7 8 </tr>
... ...