From: <al...@us...> - 2008-09-24 22:53:38
|
Revision: 701 http://sciret.svn.sourceforge.net/sciret/?rev=701&view=rev Author: alpeb Date: 2008-09-24 22:53:27 +0000 (Wed, 24 Sep 2008) Log Message: ----------- added ability for users to request the creation of a category Modified Paths: -------------- trunk/actions/SavePreferences.php trunk/flowMap.php trunk/templates/EditPreferences.tpl trunk/templates/MainView.tpl trunk/views/EditPreferences.php trunk/views/MainView.php Added Paths: ----------- trunk/actions/SaveRequestCategory.php trunk/forms/ trunk/forms/RequestCategoryForm.php trunk/templates/RequestCategory.tpl trunk/views/RequestCategory.php Modified: trunk/actions/SavePreferences.php =================================================================== --- trunk/actions/SavePreferences.php 2008-09-24 22:51:52 UTC (rev 700) +++ trunk/actions/SavePreferences.php 2008-09-24 22:53:27 UTC (rev 701) @@ -47,6 +47,7 @@ $this->configuration->setConfigValue('mailTransport', $_POST['mailTransport'] == 'smtp' ? 'smtp' : 'sendmail'); $this->configuration->setConfigValue('mailFromName', $_POST['mailFromName']); $this->configuration->setConfigValue('mailFromMail', $_POST['mailFromMail']); + $this->configuration->setConfigValue('mailCategoryRequest', $_POST['mailCategoryRequest']); $this->configuration->setConfigValue('smtpServer', $_POST['smtpServer']); $this->configuration->setConfigValue('smtpUser', $_POST['smtpUser']); $this->configuration->setConfigValue('smtpPassword', $_POST['smtpPassword']); Added: trunk/actions/SaveRequestCategory.php =================================================================== --- trunk/actions/SaveRequestCategory.php (rev 0) +++ trunk/actions/SaveRequestCategory.php 2008-09-24 22:53:27 UTC (rev 701) @@ -0,0 +1,73 @@ +<?php + +/* +* @copyright Copyright (C) 2005-2008 Keyboard Monkeys Ltd. http://www.kb-m.com +* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License +* @author Alejandro Pedraza +* @since Sciret 1.2 +* @package Sciret +* @packager Keyboard Monkeys +*/ + +require 'actions/Action.php'; + +class SaveRequestCategory extends Action +{ + public function dispatch() + { + if (!$this->configuration->getConfigValue('mailCategoryRequest')) { + $_SESSION['message'] = $this->user->lang('System Error: The admininstrator hasn\'t configured that option yet.'); + Library::redirect(Library::getLink(array('view' => 'MainView'))); + } + + $categoryGateway = new CategoryGateway(); + $form = new RequestCategoryForm(null, $this->user, $categoryGateway->getCategories()); + $this->_validateForm($form); + + $mail = new EmailGateway($this->configuration); + + $mail->AddAddress($this->configuration->getConfigValue('mailCategoryRequest')); + $mail->Subject = $this->user->lang('A user has requested a category'); + $parentCategory = new Category($form->getValue('parentCategory')); + $mail->Body = $this->user->lang('The user %s (%s) has requested the inclusion in the Knowledge Base of a category named "%s", under the category "%s"', + $form->getValue('name'), + $form->getValue('email'), + $form->getValue('newCategoryName'), + $parentCategory->getId()? $parentCategory->getLabel() : $this->user->lang('Root')); + if ($comments = $form->getValue('comments')) { + $mail->Body .= "\r\n\r\n" . $this->user->lang('The user provided these comments:'); + $mail->Body .= "\r\n\r\n$comments"; + } + + if (!$mail->Send()) { + $_SESSION['message'] = $this->user->lang('Sorry, there was a problem notifying the administrator. Please try again later.'); + Library::redirect(Library::getLink(array('view' => 'MainView'))); + } + + $_SESSION['message'] = $this->user->lang('The administrator has been notified of your request.'); + Library::redirect(Library::getLink(array('view' => 'MainView'))); + } + + private function _validateForm($form) + { + $formData = array( + 'parentCategory' => $_POST['parentCategory'], + 'newCategoryName' => $_POST['newCategoryName'], + 'comments' => $_POST['comments'], + ); + + if (!$this->user->isAnonymous()) { + $formData['name'] = $this->user->getFullName(); + $formData['email'] = $this->user->email; + } else { + $formData['name'] = $_POST['name']; + $formData['email'] = $_POST['email']; + } + + if (!$form->isValid($formData)) { + $appSession = Zend_Registry::get('appSession'); + $appSession->requestCategoryForm = $form; + Library::redirect(Library::getLink(array('view' => 'RequestCategory'))); + } + } +} Modified: trunk/flowMap.php =================================================================== --- trunk/flowMap.php 2008-09-24 22:51:52 UTC (rev 700) +++ trunk/flowMap.php 2008-09-24 22:53:27 UTC (rev 701) @@ -28,6 +28,7 @@ 'AddQuestion' => array(User::ROLE_ANONYMOUS, true, true, true, true), 'EditCategories' => array(User::ROLE_ANONYMOUS, true, true, true, true), 'EditCategory' => array(User::ROLE_ADMIN, true, true, true), + 'RequestCategory' => array(User::ROLE_ANONYMOUS, true, true, true, false), 'EditPreferences' => array(User::ROLE_ANONYMOUS, true, true, true, true), 'ManageArticles' => array(User::ROLE_REGISTERED, true, true, false), 'ManageQuestions' => array(User::ROLE_REGISTERED, true, true, true), @@ -65,6 +66,7 @@ 'DeleteUser' => array(User::ROLE_ADMIN, true), 'AddQuestion' => array(User::ROLE_ANONYMOUS, true, true), 'SaveCategory' => array(User::ROLE_ADMIN, true), + 'SaveRequestCategory' => array(User::ROLE_ANONYMOUS, true, false), 'DeleteCategory' => array(User::ROLE_ADMIN, true), 'SavePreferences' => array(User::ROLE_ANONYMOUS, true, true), 'DeleteArticle' => array(User::ROLE_REGISTERED, true), Added: trunk/forms/RequestCategoryForm.php =================================================================== --- trunk/forms/RequestCategoryForm.php (rev 0) +++ trunk/forms/RequestCategoryForm.php 2008-09-24 22:53:27 UTC (rev 701) @@ -0,0 +1,71 @@ +<?php + +class RequestCategoryForm extends Zend_Form +{ + private $_parentCategory; + + public function __construct($options = null, $user = null, $categories = array()) + { + $this->_parentCategory = new Zend_Form_Element_Select('parentCategory'); + $this->_parentCategory->setLabel('Parent Category') + ->setIsArray(false) + ->addMultiOption(0, $user->lang('Root Category')); + + foreach ($categories[0]->getChildren() as $category) { + $this->_parseCategoriesDropdown($category, 0); + } + + parent::__construct($options); + } + + private function _parseCategoriesDropdown($category, $depth = 0) + { + $indent = str_repeat(' ', $depth); + + $this->_parentCategory->addMultiOption($category->getId(), $indent . $category->getLabel()); + + if ($category->hasChildren()) { + ++$depth; + foreach ($category->getChildren() as $childCategory) { + $this->_parseCategoriesDropdown($childCategory, $depth); + } + } + } + + public function init() + { + $name = new Zend_Form_Element_Text('name'); + $name->setLabel('Your name') + ->setRequired(true); + + $email = new Zend_Form_Element_Text('email'); + $email->setLabel('E-mail') + ->addFilter('StringToLower') + ->setRequired(true) + ->addValidator('EmailAddress'); + + $newCategoryName= new Zend_Form_Element_Text('newCategoryName'); + $newCategoryName->setLabel('The name of the category you want to be included') + ->setRequired(true); + + $comments = new Zend_Form_Element_Textarea('comments'); + $comments->setLabel('Comments') + ->setAttrib('rows', 4); + + $this->AddElements(array($name, $email, $this->_parentCategory, $newCategoryName, $comments)); + } + + + /** + * Overrides Zend_Form method to fix issue + * @see http://www.nabble.com/Zend_Form-without-MVC-problem-td17375245.html + */ + public function setView(Zend_View_Interface $view) + { + parent::setView($view); + foreach ($this as $item) { + $item->setView($view); + } + return $this; + } +} Modified: trunk/templates/EditPreferences.tpl =================================================================== --- trunk/templates/EditPreferences.tpl 2008-09-24 22:51:52 UTC (rev 700) +++ trunk/templates/EditPreferences.tpl 2008-09-24 22:53:27 UTC (rev 701) @@ -156,6 +156,12 @@ </td> </tr> <tr class="row_on"> + <td style="text-align:right; font-weight:bold">[l]Send category creation request to (email)[/l]:</td> + <td> + <input type="text" name="mailCategoryRequest" value="{mailCategoryRequest}"/> + </td> + </tr> + <tr class="row_off"> <td style="text-align:right; font-weight:bold">[l]Send mail using[/l]:</td> <td> <select name="mailTransport" onchange="javascript:toggleSMTPSettings(value);"> @@ -164,7 +170,7 @@ </select> </td> </tr> - <tr class="row_off" id="smtp_options" {showSMTPOptions}> + <tr class="row_on" id="smtp_options" {showSMTPOptions}> <td colspan="2"> <p style="text-align:center; font-weight:bold">[l]SMTP settings[/l]:</p> <ul> @@ -175,7 +181,7 @@ </ul> </td> </tr> - <tr class="row_on"> + <tr class="row_off"> <td style="text-align:right; font-weight:bold"> [l]Check uploaded files for viruses[/l]:<br /> [l](You need to have <a href="http://www.clamav.net">ClamAV</a> in your system)[/l] Modified: trunk/templates/MainView.tpl =================================================================== --- trunk/templates/MainView.tpl 2008-09-24 22:51:52 UTC (rev 700) +++ trunk/templates/MainView.tpl 2008-09-24 22:53:27 UTC (rev 701) @@ -45,6 +45,11 @@ [l]Total Number of Articles in this Category:[/l] <!-- END totalNumArtsCat_block --> {numArts} + <!-- BEGIN requestCat_block --> + <div style="margin-top:10px"> + <a href="{requestCatLink}">[l]Request the creation of a category[/l]</a> + </div> + <!-- END requestCat_block --> </div> <div> <div class="title_view"> Added: trunk/templates/RequestCategory.tpl =================================================================== --- trunk/templates/RequestCategory.tpl (rev 0) +++ trunk/templates/RequestCategory.tpl 2008-09-24 22:53:27 UTC (rev 701) @@ -0,0 +1,22 @@ +<!-- +/* +* @copyright Copyright (C) 2005-2008 Keyboard Monkeys Ltd. http://www.kb-m.com +* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License +* @author Alejandro Pedraza +* @since Sciret 1.2 +* @package Sciret +* @packager Keyboard Monkeys +*/ +--> + +<form method="post" action="{formAction}"> + {formName} + {formEmail} + {formParentCategory} + {formNewCategoryName} + {formComments} + <input type="submit" id="submitRequest" value="[l]Send[/l]" /> + <script> + new YAHOO.widget.Button("submitRequest"); + </script> +</form> Modified: trunk/views/EditPreferences.php =================================================================== --- trunk/views/EditPreferences.php 2008-09-24 22:51:52 UTC (rev 700) +++ trunk/views/EditPreferences.php 2008-09-24 22:53:27 UTC (rev 701) @@ -55,6 +55,7 @@ 'passwordExpirationDays' => $this->configuration->getConfigValue('passwordExpirationDays'), 'mailFromName' => $this->configuration->getConfigValue('mailFromName'), 'mailFromMail' => $this->configuration->getConfigValue('mailFromMail'), + 'mailCategoryRequest' => $this->configuration->getConfigValue('mailCategoryRequest'), 'sendMailUsing_sendmail_selected' => $this->configuration->getConfigValue('mailTransport') == 'sendmail' ? 'selected="true" ': '', 'sendMailUsing_smtp_selected' => $this->configuration->getConfigValue('mailTransport') == 'smtp' ? 'selected="true" ': '', 'showSMTPOptions' => $this->configuration->getConfigValue('mailTransport') == 'smtp' ? '' : 'style="display:none;"', Modified: trunk/views/MainView.php =================================================================== --- trunk/views/MainView.php 2008-09-24 22:51:52 UTC (rev 700) +++ trunk/views/MainView.php 2008-09-24 22:53:27 UTC (rev 701) @@ -56,6 +56,7 @@ $this->tpl->set_block('main', 'viewAllLink_block', 'viewAllLink'); $this->tpl->set_block('main', 'viewArticlesLink_block', 'viewArticlesLink'); $this->tpl->set_block('main', 'viewBookmarksLink_block', 'viewBookmarksLink'); + $this->tpl->set_block('main', 'requestCat_block', 'requestCat'); $this->tpl->set_block('articles_block', 'question_block', 'question'); $this->tpl->set_block('unansweredQuestionsItem_block', 'answerLink_block', 'answerLink'); @@ -146,6 +147,14 @@ 'numCats' => $numCats, )); + if (!$this->user->isAdmin()) { + $this->tpl->set_var('requestCatLink', Library::getLink(array('view' => 'RequestCategory', + 'catId' => $catId))); + $this->tpl->parse('requestCat', 'requestCat_block'); + } else { + $this->tpl->set_var('requestCat', ''); + } + // ** ARTICLES LIST ** $articles = $articleGateway->getArticles( $catId, $this->user->getPreference('navigationType') == 'catAndSubCats', Added: trunk/views/RequestCategory.php =================================================================== --- trunk/views/RequestCategory.php (rev 0) +++ trunk/views/RequestCategory.php 2008-09-24 22:53:27 UTC (rev 701) @@ -0,0 +1,65 @@ +<?php + +/* +* @copyright Copyright (C) 2005-2008 Keyboard Monkeys Ltd http://www.kb-m.com +* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License +* @author Alejandro Pedraza +* @since Sciret 1.0 +* @package Sciret +* @packager Keyboard Monkeys +*/ + +require_once 'views/View.php'; + +class RequestCategory extends View +{ + public function dispatch() + { + if (!isset($_GET['catId'])) { + $_GET['catId'] = 0; + } + $_GET['catId'] = (int)$_GET['catId']; + + $this->tpl->set_file('main', 'RequestCategory.tpl'); + $this->tpl->set_var(array( + 'formAction' => Library::getLink(array('action' => 'SaveRequestCategory')), + )); + + $categoryGateway = new CategoryGateway(); + + $appSession = Zend_Registry::get('appSession'); + if (isset($appSession->requestCategoryForm)) { + $form = $appSession->requestCategoryForm; + unset($appSession->requestCategoryForm); + } else { + $form = new RequestCategoryForm(null, $this->user, $categoryGateway->getCategories()); + $form->parentCategory->setValue($_GET['catId']); + } + + $view = new Zend_View(); + + // to avoid the being escaped in the categories dropdown + $view->setEscape('stripslashes'); + + $form->setView($view); + $this->tpl->set_var(array( + 'formParentCategory' => $form->parentCategory, + 'formNewCategoryName' => $form->newCategoryName, + 'formComments' => $form->comments, + )); + + if ($this->user->isAnonymous()) { + $this->tpl->set_var(array( + 'formName' => $form->name, + 'formEmail' => $form->email, + )); + } else { + $this->tpl->set_var(array( + 'formName' => '', + 'formEmail' => '', + )); + } + + $this->tpl->pparse('out', 'main'); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |