From: <gem...@li...> - 2011-10-21 12:15:53
|
Revision: 123 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=123&view=rev Author: matijsdejong Date: 2011-10-21 12:15:43 +0000 (Fri, 21 Oct 2011) Log Message: ----------- Saving last changes Added Paths: ----------- branches/newUser/classes/Gems/Model/UserModel.php branches/newUser/classes/Gems/User/ branches/newUser/classes/Gems/User/ProjectSuperUser.php branches/newUser/classes/Gems/User/UserAbstract.php branches/newUser/classes/Gems/User/UserInterface.php branches/newUser/classes/Gems/User/UserLoader.php branches/newUser/configs/db/tables/gems__users.10.sql Added: branches/newUser/classes/Gems/Model/UserModel.php =================================================================== --- branches/newUser/classes/Gems/Model/UserModel.php (rev 0) +++ branches/newUser/classes/Gems/Model/UserModel.php 2011-10-21 12:15:43 UTC (rev 123) @@ -0,0 +1,117 @@ +<?php + +/** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * @package Gems + * @subpackage Model + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $ + */ + +/** + * + * + * @package Gems + * @subpackage Model + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.4.4 + */ +class Gems_Model_UserModel extends Gems_Model_JoinModel +{ + /** + * The length of a user id. + * + * @var int + */ + protected $userIdLen = 8; + + /** + * Create a model that joins two or more tables + * + * @param string $name The name of the model + * @param string $secondTable The optional second base table for the model + * @param array $joinFields Array of source->dest primary keys for this join + * @param string $fieldPrefix Prefix to use for change fields (date/userid) + * @param bool $saveable Will changes to this table be saved + */ + public function __construct($name, $secondTable = null, array $joinFields = null, $fieldPrefix = null, $saveable = null) + { + parent::__construct($name, 'gems__users', (null === $saveable ? $fieldPrefix : $saveable)); + + if ($fieldPrefix) { + Gems_Model::setChangeFieldsByPrefix($this, 'gsu'); + } + + if ($secondTable) { + $this->addTable($secondTable, $joinFields, $fieldPrefix, $saveable); + } + } + + /** + * Finds a random unique user id. + * + * @return int + */ + protected function _createUserId() + { + $max = $this->userIdLen; + + do { + $out = mt_rand(1, 9); + for ($i = 1; $i < $this->userIdLen; $i++) { + $out .= mt_rand(0, 9); + } + // Make it a number + $out = intval($out); + + } while ($this->db->fetchOne('SELECT gsu_id_user FROM gems__users WHERE gsu_id_user = ?', $out)); + + return $out; + } + + /** + * Save a single model item. + * + * @param array $newValues The values to store for a single model item. + * @param array $filter If the filter contains old key values these are used + * to decide on update versus insert. + * @return array The values as they are after saving (they may change). + */ + public function save(array $newValues, array $filter = null, array $saveTables = null) + { + if (! (isset($newValues['gsu_id_user']) && $newValues['gsu_id_user'])) { + // Load a new user id if needed + $newValues['gsu_id_user'] = $this->_createUserId(); + } + + parent::save($newValues, $filter, $saveTables); + } +} Property changes on: branches/newUser/classes/Gems/User ___________________________________________________________________ Added: bugtraq:url + http://survey.erasmusmc.nl/support/mantis/view.php?id=%BUGID% Added: bugtraq:number + true Added: bugtraq:logregex + #(\d+) Added: branches/newUser/classes/Gems/User/ProjectSuperUser.php =================================================================== --- branches/newUser/classes/Gems/User/ProjectSuperUser.php (rev 0) +++ branches/newUser/classes/Gems/User/ProjectSuperUser.php 2011-10-21 12:15:43 UTC (rev 123) @@ -0,0 +1,120 @@ +<?php + +/** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * @package Gems + * @subpackage + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $ + */ + +/** + * + * + * @package Gems + * @subpackage + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.4.4 + */ +class Gems_User_ProjectSuperUser extends Gems_User_UserAbstract +{ + const MIN_PASSWORD_LENGTH = 10; + + /** + * The role of this user. + * + * @var string + */ + protected $_role = 'super'; + + /** + * + * @var ArrayObject + */ + protected $project; + + /** + * + * @var Gems_Util_Translated + */ + protected $translated; + + /** + * Check that the password is correct for this user. + * + * @param string $password Unencrypted password + * @return boolean + */ + public function checkPassword($password) + { + if (isset($this->project->admin['pwd']) && ($this->project->admin['pwd'] == $password)) { + if (APPLICATION_ENV === 'production') { + if (strlen($string) < self::MIN_PASSWORD_LENGTH) { + throw new Gems_Exception(sprintf($this->translated->_('The password for the super user should be at least %s characters long on production systems.'), self::MIN_PASSWORD_LENGTH)); + } + } + + return true; + } + + return false; + } + + /** + * Returns true if the role of this user has the given privilege. + * + * @param string $privilege + * @return bool + */ + public function hasPrivilege($privilege) + { + // Overloaded!! + // + // Return true also for any not 'nologin' privilege + return parent::hasPrivilege($privilege) || (! $this->acl) || (! $this->acl->isAllowed('nologin', null, $privilege)); + } + + /** + * Intialize the values for this user. + * + * Skipped when the user is the active user and is stored in the session. + * + * @param string $login_name + * @param int $organization Only used when more than one organization uses this $login_name + * @return boolean False when the object could not load. + */ + protected function initVariables($login_name, $organization) + { + $this->setRole('super'); + return true; + } + +} Added: branches/newUser/classes/Gems/User/UserAbstract.php =================================================================== --- branches/newUser/classes/Gems/User/UserAbstract.php (rev 0) +++ branches/newUser/classes/Gems/User/UserAbstract.php 2011-10-21 12:15:43 UTC (rev 123) @@ -0,0 +1,288 @@ +<?php + +/** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * @package Gems + * @subpackage User + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $ + */ + +/** + * + * + * @package Gems + * @subpackage User + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.4.4 + */ +abstract class Gems_User_UserAbstract extends Gems_Registry_TargetAbstract implements Gems_User_UserInterface +{ + /** + * + * @var string + */ + private $_login_name; + + /** + * + * @var int + */ + private $_organization_id; + + /** + * + * @var mixed ArrayObject or Zend_Session_Namespace + */ + private $_vars; + + /** + * + * @var MUtil_Acl + */ + protected $acl; + + /** + * The escort session. + * + * For compatibility reasons only. + * + * @var Zend_Session_Namespace + */ + protected $session; + + /** + * + * @param string $login_name + * @param int $organization Only used when more than one organization uses this $login_name + */ + public function __construct($login_name, $organization) + { + $this->_login_name = $login_name; + $this->_organization_id = $organization; + } + + /** + * Returns the session namespace containing user data. + * + * @staticvar Zend_Session_Namespace $session + * @return Zend_Session_Namespace + */ + private static function _getSessionStore() + { + static $session; + + if (! $session) { + $session = new Zend_Session_Namespace('gems.' . GEMS_PROJECT_NAME . '.userdata', true); + } + + return $session; + } + + /** + * The store currently used. + * + * @return mixed ArrayObject or Zend_Session_Namespace + */ + private function _getVariableStore() + { + $loginName = 'loginName'; + $organizationId = 'organizationId'; + + if (! $this->_vars) { + $sessionStore = self::_getSessionStore(); + + if (isset($sessionStore->$loginName, $sessionStore->$organizationId) && ($sessionStore->$loginName == $this->_login_name) && ($sessionStore->$organizationId == $this->_organization_id)) { + $this->_vars = $sessionStore; + $this->_vars->__set($loginName, $this->_login_name); + $this->_vars->__set($organizationId, $this->_organization_id); + } else { + $this->_vars = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); + $this->_vars->offsetSet($loginName, $this->_login_name); + $this->_vars->offsetSet($organizationId, $this->_organization_id); + } + + } + + return $this->_vars; + } + + /** + * Should be called after answering the request to allow the Target + * to check if all required registry values have been set correctly. + * + * @return boolean False if required variables are missing. + */ + public function checkRegistryRequestsAnswers() + { + if ($this->_getVariableStore() instanceof Zend_Session_Namespace) { + $init = true; + } else { + $init = $this->initVariables($this->_login_name, $this->_organization_id); + } + + return $init && parent::checkRegistryRequestsAnswers(); + } + + /** + * + * @return string + */ + protected function getLoginName() + { + return $this->_login_name; + } + + /** + * + * @return int + */ + protected function getOrganizationId() + { + return $this->_organization_id; + } + + /** + * Returns the (current) role of this user. + * + * @return string + */ + public function getRole() + { + return $this->getVar('user_role'); + } + + /** + * Get a value in whatever store is used by this object. + * + * @param string $name + * @return mixed + */ + protected function getVar($name) + { + $store = $this->_getVariableStore(); + + if ($store instanceof Zend_Session_Namespace) { + if ($store->__isset($name)) { + return $store->__get($name); + } + } else { + if ($store->offsetExists($name)) { + return $store->offsetSet($name); + } + } + return null; + } + + /** + * Returns true if the role of this user has the given privilege. + * + * @param string $privilege + * @return bool + */ + public function hasPrivilege($privilege) + { + return (! $this->acl) || $this->acl->isAllowed($this->getRole(), null, $privilege); + } + + /** + * Intialize the values for this user. + * + * Skipped when the user is the active user and is stored in the session. + * + * @param string $login_name + * @param int $organization Only used when more than one organization uses this $login_name + * @return boolean False when the object could not load. + */ + abstract protected function initVariables($login_name, $organization); + + /** + * Set this user as the current user. + * + * This means that the data about this user will be stored in a session. + * + * @return Gems_User_UserAbstract + */ + public function setAsCurrentUser() + { + // Get the current variables + $oldStore = $this->_getVariableStore(); + + // When $oldStore is a Zend_Session_Namespace, then this user is already the current user. + if (! $oldStore instanceof Zend_Session_Namespace) { + $this->_vars = self::_getSessionStore(); + + // Clean up what is there now. + $this->_vars->unsetAll(); + $this->session->unsetAll(); + + foreach ($oldStore as $name => $value) { + $this->_vars->__set($name, $value); + $this->session->__set($name, $value); + } + + } + + return $this; + } + + /** + * Sets the (current) role of this user. + * + * @param string $value Role + * @return Gems_User_UserAbstract (continuation pattern) + */ + protected function setRole($value) + { + $this->setVar('user_role', $value); + + return $this; + } + + /** + * Store a value in whatever store is used by this object. + * + * @param string $name + * @param mixed $value + * @return Gems_User_UserAbstract (continuation pattern) + */ + protected function setVar($name, $value) + { + $store = $this->_getVariableStore(); + + if ($store instanceof Zend_Session_Namespace) { + $store->__set($name, $value); + } else { + $store->offsetSet($name, $value); + } + return $this; + } +} Added: branches/newUser/classes/Gems/User/UserInterface.php =================================================================== --- branches/newUser/classes/Gems/User/UserInterface.php (rev 0) +++ branches/newUser/classes/Gems/User/UserInterface.php 2011-10-21 12:15:43 UTC (rev 123) @@ -0,0 +1,60 @@ +<?php + +/** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * @package Gems + * @subpackage User + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $ + */ + +/** + * + * + * @package Gems + * @subpackage User + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.4.4 + */ +interface Gems_User_UserInterface +{ + /** + * Check that the password is correct for this user. + * + * @param string $password Unencrypted password + * @return boolean + */ + public function checkPassword($password); + + public function hasPrivilege($privilege); + + public function setAsCurrentUser(); +} Added: branches/newUser/classes/Gems/User/UserLoader.php =================================================================== --- branches/newUser/classes/Gems/User/UserLoader.php (rev 0) +++ branches/newUser/classes/Gems/User/UserLoader.php 2011-10-21 12:15:43 UTC (rev 123) @@ -0,0 +1,85 @@ +<?php + +/** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * @package Gems + * @subpackage User + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $ + */ + +/** + * Loads users. + * + * @package Gems + * @subpackage User + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.4.4 + */ +class Gems_User_UserLoader extends Gems_Loader_TargetLoaderAbstract +{ + /** + * Allows sub classes of Gems_Loader_LoaderAbstract to specify the subdirectory where to look for. + * + * @var string $cascade An optional subdirectory where this subclass always loads from. + */ + protected $cascade = 'User'; + + /** + * + * @var ArrayObject + */ + protected $project; + + + /** + * + * @param string $login_name + * @param int $organization Only used when more than one organization uses this $login_name + * @return Gems_User_UserInterface + */ + public function getUser($login_name, $organization) + { + if ($this->isProjectUser($login_name)) { + return $this->loadProjectUser($login_name, $organization); + } + } + + protected function isProjectUser($login_name) + { + return isset($this->project->admin['user']) && ($this->project->admin['user'] == $login_name); + } + + protected function loadProjectUser($login_name, $organization) + { + return $this->_getClass('ProjectSuperUser', null, array($login_name, $organization)); + } +} Added: branches/newUser/configs/db/tables/gems__users.10.sql =================================================================== --- branches/newUser/configs/db/tables/gems__users.10.sql (rev 0) +++ branches/newUser/configs/db/tables/gems__users.10.sql 2011-10-21 12:15:43 UTC (rev 123) @@ -0,0 +1,31 @@ + +-- Table containing the users that are allowed to login +-- +CREATE TABLE if not exists gems__users ( + gsu_id_user bigint unsigned not null, + + gsu_login varchar(30) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null, + gsu_id_organization bigint not null references gems__organizations (gor_id_organization), + + gsu_user_class varchar(30) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null, + gsu_active boolean not null default 1, + + -- Common fields for standard 'store password in Gems' logins + -- Not every gsu_user_class will use them + gsu_password varchar(32) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null, + gsu_failed_logins int(11) unsigned not null default 0, + gsu_last_failed timestamp null, + gsu_reset_key varchar(64) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null, + gsu_reset_requested timestamp null, + gsu_reset_required boolean not null default 0, + + gsu_changed timestamp not null default current_timestamp on update current_timestamp, + gsu_changed_by bigint unsigned not null, + gsu_created timestamp not null, + gsu_created_by bigint unsigned not null, + + PRIMARY KEY(gsu_id_user), + UNIQUE(gsu_login, gsu_id_organization) + ) + ENGINE=InnoDB + CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-21 12:29:46
|
Revision: 124 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=124&view=rev Author: matijsdejong Date: 2011-10-21 12:29:37 +0000 (Fri, 21 Oct 2011) Log Message: ----------- Merge from trunk r144-r122 Revision Links: -------------- http://gemstracker.svn.sourceforge.net/gemstracker/?rev=144&view=rev http://gemstracker.svn.sourceforge.net/gemstracker/?rev=122&view=rev Modified Paths: -------------- branches/newUser/classes/Gems/Default/MailLogAction.php branches/newUser/classes/Gems/Default/ProjectInformationAction.php branches/newUser/classes/Gems/Default/SourceAction.php branches/newUser/classes/Gems/Menu/MenuAbstract.php branches/newUser/classes/Gems/Menu/SubMenuItem.php branches/newUser/classes/Gems/Snippets/ModelTableSnippetAbstract.php branches/newUser/classes/Gems/Tracker/Survey.php branches/newUser/classes/Gems/Tracker.php branches/newUser/classes/Gems/Util/DatabasePatcher.php branches/newUser/classes/GemsEscort.php branches/newUser/classes/MUtil/Controller/ModelSnippetActionAbstract.php branches/newUser/classes/MUtil/Snippets/ModelTableSnippetAbstract.php branches/newUser/configs/db/patches.sql branches/newUser/configs/db/tables/gems__mail_jobs.300.sql branches/newUser/configs/db/tables/gems__reception_codes.10.sql branches/newUser/configs/db/tables/gems__roles.20.sql branches/newUser/configs/db/tables/gems__surveys.30.sql branches/newUser/controllers/MailLogController.php branches/newUser/languages/default-en.mo branches/newUser/languages/default-en.po branches/newUser/languages/default-nl.mo branches/newUser/languages/default-nl.po branches/newUser/snippets/Generic/ModelItemTableSnippet.php branches/newUser/snippets/Generic/ModelTableSnippet.php Added Paths: ----------- branches/newUser/classes/Gems/Snippets/ModelTableSnippetGeneric.php branches/newUser/snippets/Mail/ branches/newUser/snippets/Mail/Log/ branches/newUser/snippets/Mail/Log/MailLogBrowseSnippet.php Removed Paths: ------------- branches/newUser/classes/Gems/Default/MailLogActionOldStyle.php branches/newUser/snippets/Mail/Log/ branches/newUser/snippets/Mail/Log/MailLogBrowseSnippet.php Property Changed: ---------------- branches/newUser/ Property changes on: branches/newUser ___________________________________________________________________ Added: svn:mergeinfo + /trunk/library:114-122 Modified: branches/newUser/classes/Gems/Default/MailLogAction.php =================================================================== --- branches/newUser/classes/Gems/Default/MailLogAction.php 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/classes/Gems/Default/MailLogAction.php 2011-10-21 12:29:37 UTC (rev 124) @@ -37,10 +37,8 @@ */ /** - * Short description for class + * Controller for looking at mail activity * - * Long description for class (if any)... - * * @package Gems * @subpackage Default * @copyright Copyright (c) 2011 Erasmus MC @@ -50,28 +48,12 @@ class Gems_Default_MailLogAction extends Gems_Controller_ModelSnippetActionAbstract { /** - * Adds columns from the model to the bridge that creates the browse table. + * The snippets used for the autofilter action. * - * Adds a button column to the model, if such a button exists in the model. - * - * @param MUtil_Model_TableBridge $bridge - * @param MUtil_Model_ModelAbstract $model - * @rturn void + * @var mixed String or array of snippets name */ - public function addTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) - { - if ($menuItem = $this->firstAllowedMenuItem('show')) { - $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge)); - } + protected $autofilterSnippets = 'Mail_Log_MailLogBrowseSnippet'; - // Newline placeholder - $br = MUtil_Html::create('br'); - - $bridge->addMultiSort('grco_created', $br, 'respondent_name', $br, 'grco_address'); - $bridge->addMultiSort('grco_id_token', $br, 'assigned_by', $br, 'grco_sender'); - $bridge->addMultiSort('grco_topic'); - } - /** * The automatically filtered result */ @@ -79,7 +61,6 @@ { $filter = array('grco_organization' => $this->escort->getCurrentOrganization()); - $this->autofilterParameters['addTableColumns'] = array($this, 'addTableColumns'); $this->autofilterParameters['extraFilter'] = $filter; $this->autofilterParameters['extraSort'] = array('grco_created' => SORT_DESC); @@ -147,7 +128,6 @@ { $this->html->h3($this->_('Mail Activity Log')); - // MUtil_Echo::track($this->indexParameters); parent::indexAction(); } Deleted: branches/newUser/classes/Gems/Default/MailLogActionOldStyle.php =================================================================== --- branches/newUser/classes/Gems/Default/MailLogActionOldStyle.php 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/classes/Gems/Default/MailLogActionOldStyle.php 2011-10-21 12:29:37 UTC (rev 124) @@ -1,150 +0,0 @@ -<?php - -/** - * Copyright (c) 2011, Erasmus MC - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Erasmus MC nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Short description of file - * - * @package Gems - * @subpackage Default - * @author Matijs de Jong <mj...@ma...> - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $ - */ - -/** - * Temprary class until Gems_Controller_ModelSnippetActionAbstract works - * - * @package Gems - * @subpackage Default - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @since Class available since version 1.4.2 - */ -class Gems_Default_MailLogActionOldStyle extends Gems_Controller_BrowseEditAction -{ - public $sortKey = array('grco_created' => SORT_DESC); - - /** - * Adds columns from the model to the bridge that creates the browse table. - * - * Adds a button column to the model, if such a button exists in the model. - * - * @param MUtil_Model_TableBridge $bridge - * @param MUtil_Model_ModelAbstract $model - * @rturn void - */ - protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) - { - if ($menuItem = $this->findAllowedMenuItem('show')) { - $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge)); - } - - // Newline placeholder - $br = MUtil_Html::create('br'); - - $bridge->addMultiSort('grco_created', $br, 'respondent_name', $br, 'grco_address'); - $bridge->addMultiSort('grco_id_token', $br, 'assigned_by', $br, 'grco_sender'); - $bridge->addMultiSort('grco_topic'); - } - - /** - * Creates a model for getModel(). Called only for each new $action. - * - * The parameters allow you to easily adapt the model to the current action. The $detailed - * parameter was added, because the most common use of action is a split between detailed - * and summarized actions. - * - * @param boolean $detailed True when the current action is not in $summarizedActions. - * @param string $action The current action. - * @return MUtil_Model_ModelAbstract - */ - public function createModel($detailed, $action) - { - $model = new Gems_Model_JoinModel('maillog', 'gems__log_respondent_communications'); - - $model->addLeftTable('gems__respondents', array('grco_id_to' => 'grs_id_user')); - $model->addLeftTable('gems__staff', array('grco_id_by' => 'gsf_id_user')); - $model->addLeftTable('gems__mail_templates', array('grco_id_message' => 'gmt_id_message')); - - $model->addColumn( - "TRIM(CONCAT(COALESCE(CONCAT(grs_last_name, ', '), '-, '), COALESCE(CONCAT(grs_first_name, ' '), ''), COALESCE(grs_surname_prefix, '')))", - 'respondent_name'); - $model->addColumn( - "CASE WHEN gems__staff.gsf_id_user IS NULL - THEN '-' - ELSE - CONCAT( - COALESCE(gems__staff.gsf_last_name, ''), - ', ', - COALESCE(gems__staff.gsf_first_name, ''), - COALESCE(CONCAT(' ', gems__staff.gsf_surname_prefix), '') - ) - END", - 'assigned_by'); - - $model->resetOrder(); - - $model->set('grco_created', 'label', $this->_('Date sent')); - $model->set('respondent_name', 'label', $this->_('Receiver')); - $model->set('grco_address', 'label', $this->_('To address'), 'itemDisplay', 'MUtil_Html_AElement::ifmail'); - $model->set('assigned_by', 'label', $this->_('Sender')); - $model->set('grco_sender', 'label', $this->_('From address'), 'itemDisplay', 'MUtil_Html_AElement::ifmail'); - $model->set('grco_id_token', 'label', $this->_('Token')); - $model->set('grco_topic', 'label', $this->_('Subject')); - - if ($detailed) { - $model->set('gmt_subject', 'label', $this->_('Template')); - } else { - $model->set('grco_created', 'formatFunction', $this->util->getTranslated()->formatDate); - } - - return $model; - } - - /** - * Helper function to allow generalized statements about the items in the model. - * - * @param int $count - * @return $string - */ - public function getTopic($count = 1) - { - return $this->plural('Activity Log', 'Activity Logs', $count); - } - - - /** - * Helper function to allow generalized treatment of the header. - * - * return $string - */ - public function getTopicTitle() - { - return $this->_('Mail Activity Log'); - } -} Modified: branches/newUser/classes/Gems/Default/ProjectInformationAction.php =================================================================== --- branches/newUser/classes/Gems/Default/ProjectInformationAction.php 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/classes/Gems/Default/ProjectInformationAction.php 2011-10-21 12:29:37 UTC (rev 124) @@ -45,6 +45,18 @@ */ class Gems_Default_ProjectInformationAction extends Gems_Controller_Action { + /** + * + * @var GemsEscort + */ + public $escort; + + /** + * + * @var Gems_Menu + */ + public $menu; + public $useHtmlView = true; protected function _showTable($caption, $data, $nested = false) @@ -132,18 +144,40 @@ $data[$this->_('Server OS')] = php_uname('s'); $data[$this->_('Time on server')] = date('r'); + if (file_exists($this->escort->getMaintenanceLockFilename())) { + $label = $this->_('Turn Maintenance Mode OFF'); + } else { + $label = $this->_('Turn Maintenance Mode ON'); + } + $request = $this->getRequest(); + $buttonList = $this->menu->getMenuList(); + $buttonList->addParameterSources($request) + ->addByController($request->getControllerName(), 'maintenance', $label); + + // $this->html->buttonDiv($buttonList); + $this->_showTable($this->_('Version information'), $data); + + $this->html->buttonDiv($buttonList); } public function maintenanceAction() { - $lockFile = GEMS_ROOT_DIR . '/var/settings/lock.txt'; - if(file_exists($lockFile)) { + $lockFile = $this->escort->getMaintenanceLockFilename(); + if (file_exists($lockFile)) { unlink($lockFile); } else { touch($lockFile); } - $this->_forward('index'); + + // Dump the existing maintenance mode messages. + $this->escort->getMessenger()->clearCurrentMessages(); + $this->escort->getMessenger()->clearMessages(); + MUtil_Echo::out(); + + // Redirect + $request = $this->getRequest(); + $this->_reroute(array($request->getActionKey() => 'index')); } public function phpAction() Modified: branches/newUser/classes/Gems/Default/SourceAction.php =================================================================== --- branches/newUser/classes/Gems/Default/SourceAction.php 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/classes/Gems/Default/SourceAction.php 2011-10-21 12:29:37 UTC (rev 124) @@ -76,14 +76,14 @@ } $bridge->addHidden('gso_id_source'); - $bridge->addText('gso_source_name', array('size' => 15, 'minlength' => 4)); + $bridge->addText('gso_source_name', 'description', $this->_('E.g. the name of the project - for single source projects.'), 'size', 15, 'minlength', 4); $bridge->addValidator('gso_source_name', $model->createUniqueValidator('gso_source_name')); - $bridge->addText('gso_ls_url', array('size' => 50)); + $bridge->addText('gso_ls_url', 'description', $this->_('For creating token-survey url.'), 'size', 50); $bridge->addValidator('gso_ls_url', $model->createUniqueValidator('gso_ls_url')); $bridge->addValidator('gso_ls_url', new MUtil_Validate_Url()); $bridge->addSelect('gso_ls_class'); - $bridge->addSelect('gso_ls_adapter'); + $bridge->addSelect('gso_ls_adapter', 'description', $this->_('The database server used by the source.')); $bridge->addText('gso_ls_table_prefix', array('size' => 15, 'description' => $this->_('Do not forget the underscores.'))); $bridge->addText('gso_ls_dbhost', array('size' => 15, 'description' => $in_gems)); @@ -140,15 +140,16 @@ $model = new MUtil_Model_TableModel('gems__sources'); $model->set('gso_source_name', 'label', $this->_('Name')); - $model->set('gso_ls_url', 'label', $this->_('Url'), 'default', 'http://'); + $model->set('gso_ls_url', 'label', $this->_('Source Url'), 'default', 'http://'); $model->set('gso_ls_class', 'label', $this->_('Adaptor class'), 'multiOptions', $tracker->getSourceClasses()); if ($detailed) { - $model->set('gso_ls_adapter', 'label', $this->_('DB Adaptor'), 'multiOptions', $tracker->getSourceDatabaseClasses()); + $model->set('gso_ls_adapter', 'label', $this->_('Database Server'), 'multiOptions', $tracker->getSourceDatabaseClasses(), 'default', substr(get_class($this->db), strlen('Zend_Db_Adapter_'))); $model->set('gso_ls_dbhost', 'label', $this->_('Database host')); $model->set('gso_ls_database', 'label', $this->_('Database')); } + $model->set('gso_ls_table_prefix', 'label', $this->_('Table prefix'), 'default', 'ls__'); $model->set('gso_active', 'default', 0); Modified: branches/newUser/classes/Gems/Menu/MenuAbstract.php =================================================================== --- branches/newUser/classes/Gems/Menu/MenuAbstract.php 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/classes/Gems/Menu/MenuAbstract.php 2011-10-21 12:29:37 UTC (rev 124) @@ -230,7 +230,7 @@ // MAIL ACTIVITY CONTROLLER //$setup->addBrowsePage(); - $page = $setup->addPage($this->_('Activity'), 'pr.mail.log', 'mail-log'); + $page = $setup->addPage($this->_('Activity log'), 'pr.mail.log', 'mail-log'); $page->addAutofilterAction(); $page->addExcelAction(); $page->addShowAction(); @@ -300,7 +300,7 @@ $page->addAction($this->_('PHP'), null, 'php'); $page->addAction($this->_('Project'), null, 'project'); $page->addAction($this->_('Session'), null, 'session'); - $page->addAction($this->_('Maintenance mode'), 'pr.maintenance', 'maintenance'); + $page->addButtonOnly($this->_('Maintenance mode'), 'pr.maintenance', 'project-information', 'maintenance'); return $page; } Modified: branches/newUser/classes/Gems/Menu/SubMenuItem.php =================================================================== --- branches/newUser/classes/Gems/Menu/SubMenuItem.php 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/classes/Gems/Menu/SubMenuItem.php 2011-10-21 12:29:37 UTC (rev 124) @@ -551,11 +551,12 @@ return $menu; } - public function applyHiddenParameters(Gems_Menu_ParameterSource $source) + public function applyHiddenParameters(Zend_Controller_Request_Abstract $request, Gems_Menu_ParameterSource $source) { if ($this->_hiddenParameters) { - foreach ($this->_hiddenParameters as $key => $name) { - $source[$key] = $name; + foreach ($this->_hiddenParameters as $key => $value) { + $request->setParam($key, $value); + $source[$key] = $value; } } Modified: branches/newUser/classes/Gems/Snippets/ModelTableSnippetAbstract.php =================================================================== --- branches/newUser/classes/Gems/Snippets/ModelTableSnippetAbstract.php 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/classes/Gems/Snippets/ModelTableSnippetAbstract.php 2011-10-21 12:29:37 UTC (rev 124) @@ -103,6 +103,24 @@ protected $sortParamDesc = 'dsrt'; /** + * Adds columns from the model to the bridge that creates the browse table. + * + * Overrule this function to add different columns to the browse table, without + * having to recode the core table building code. + * + * @param MUtil_Model_TableBridge $bridge + * @param MUtil_Model_ModelAbstract $model + * @return void + */ + protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) + { + // make sure search results are highlighted + $this->applyTextMarker(); + + return parent::addBrowseTableColumns($bridge, $model); + } + + /** * Add the paginator panel to the table. * * Only called when $this->browse is true. Overrule this function @@ -116,6 +134,30 @@ } /** + * Make sure generic search text results are marked + * + * @return void + */ + protected function applyTextMarker() + { + $model = $this->getModel(); + + $textKey = $model->getTextFilter(); + $filter = $model->getFilter(); + + if (isset($filter[$textKey])) { + $searchText = $filter[$textKey]; + // MUtil_Echo::r('[' . $searchText . ']'); + $marker = new MUtil_Html_Marker($model->getTextSearches($searchText), 'strong', 'UTF-8'); + foreach ($model->getItemNames() as $name) { + if ($model->get($name, 'label')) { + $model->set($name, 'markCallback', array($marker, 'mark')); + } + } + } + } + + /** * Should be called after answering the request to allow the Target * to check if all required registry values have been set correctly. * @@ -204,7 +246,7 @@ $data = $this->requestCache->getProgramParams(); $model->applyParameters($data); - + } else { parent::processFilterAndSort($model); } Copied: branches/newUser/classes/Gems/Snippets/ModelTableSnippetGeneric.php (from rev 122, trunk/library/classes/Gems/Snippets/ModelTableSnippetGeneric.php) =================================================================== --- branches/newUser/classes/Gems/Snippets/ModelTableSnippetGeneric.php (rev 0) +++ branches/newUser/classes/Gems/Snippets/ModelTableSnippetGeneric.php 2011-10-21 12:29:37 UTC (rev 124) @@ -0,0 +1,94 @@ +<?php + +/** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * @package MUtil + * @subpackage Snippets + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ + */ + +/** + * Displays multiple items from a model in a tabel by row using + * the model set through the $model snippet parameter. + * + * If you want to use this class "as is" use the 'Generic_ModelTableSnippet' snippet. + * + * This class is not in the standard snippet loading directories and does not follow + * their naming conventions, but exists only to make it simple to extend this class + * for a specific implementation. + * + * @package MUtil + * @subpackage Snippets + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.4.4 + */ +class Gems_Snippets_ModelTableSnippetGeneric extends Gems_Snippets_ModelTableSnippetAbstract +{ + /** + * + * @var MUtil_Model_ModelAbstract + */ + protected $model; + + /** + * + * @var Gems_Util + */ + protected $util; + + /** + * Automatically add request cacge + * + * Should be called after answering the request to allow the Target + * to check if all required registry values have been set correctly. + * + * @return boolean False if required are missing. + */ + public function checkRegistryRequestsAnswers() + { + if ($this->util && (! $this->requestCache)) { + $this->requestCache = $this->util->getRequestCache(); + } + + return parent::checkRegistryRequestsAnswers(); + } + + /** + * Creates the model + * + * @return MUtil_Model_ModelAbstract + */ + protected function createModel() + { + return $this->model; + } +} Modified: branches/newUser/classes/Gems/Tracker/Survey.php =================================================================== --- branches/newUser/classes/Gems/Tracker/Survey.php 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/classes/Gems/Tracker/Survey.php 2011-10-21 12:29:37 UTC (rev 124) @@ -104,6 +104,26 @@ } /** + * Makes sure the receptioncode data is part of the $this->_gemsData + * + * @param boolean $reload Optional parameter to force reload. + */ + private function _ensureGroupData($reload = false) + { + if ($reload || (! isset($this->_gemsSurvey['ggp_id_group']))) { + $sql = "SELECT * FROM gems__groups WHERE ggp_id_group = ?"; + $code = $this->_gemsSurvey['gsu_id_primary_group']; + + if ($row = $this->db->fetchRow($sql, $code)) { + $this->_gemsSurvey = $row + $this->_gemsSurvey; + } else { + $name = $this->getName(); + throw new Gems_Exception("Group code $code is missing for survey '$name'."); + } + } + } + + /** * Update the survey, both in the database and in memory. * * @param array $values The values that this token should be set to @@ -466,6 +486,20 @@ } /** + * Should this survey be filled in by staff members. + * + * @return boolean + */ + public function isTakenByStaff() + { + if (! isset($this->_gemsSurvey['ggp_staff_members'])) { + $this->_ensureGroupData(); + } + + return (boolean) $this->_gemsSurvey['ggp_staff_members']; + } + + /** * Update the survey, both in the database and in memory. * * @param array $values The values that this token should be set to Modified: branches/newUser/classes/Gems/Tracker.php =================================================================== --- branches/newUser/classes/Gems/Tracker.php 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/classes/Gems/Tracker.php 2011-10-21 12:29:37 UTC (rev 124) @@ -73,7 +73,7 @@ * @var array Of classname => description */ protected $_sourceClasses = array( - 'LimeSurvey1m9Database' => 'Lime Survey 1.90 DB', + 'LimeSurvey1m9Database' => 'Lime Survey 1.90 DB', 'LimeSurvey1m91Database' => 'Lime Survey 1.91+ DB', ); @@ -114,29 +114,29 @@ private $_trackEngines = array(); /** + * Allows sub classes of Gems_Loader_LoaderAbstract to specify the subdirectory where to look for. * - * @var Zend_Translate + * @var string $cascade An optional subdirectory where this subclass always loads from. */ - protected $translate; + protected $cascade = 'Tracker'; /** * - * @var Zend_Session + * @var Zend_Db_Adapter_Abstract */ - protected $session; + protected $db; /** - * Allows sub classes of Gems_Loader_LoaderAbstract to specify the subdirectory where to look for. * - * @var string $cascade An optional subdirectory where this subclass always loads from. + * @var Zend_Translate */ - protected $cascade = 'Tracker'; + protected $translate; /** * - * @var Zend_Db_Adapter_Abstract + * @var Zend_Session */ - protected $db; + protected $session; /** * Set to true to get detailed information on all tracker actions @@ -413,12 +413,18 @@ // TODO: this should be moved to Gems_Tracker_Source_SourceInterface, // but do not have time to implement is of minor importance at this moment. - return array( - '' => '-- none --', - 'Mysqli' => 'MySQL', - 'Pdo_Mysql' => 'MySQL (PDO)', - 'Sqlsrv' => 'SQL Server', - 'Pdo_Mssql' => 'SQL Server (PDO)'); + // If the project uses Pdo database, use Pdo classes, otherwise MySQL + if (stripos(get_class($this->db), '_Pdo_')) { + return array( + '' => '-- none --', + 'Pdo_Mysql' => 'MySQL (PDO)', + 'Pdo_Mssql' => 'SQL Server (PDO)'); + } else { + return array( + '' => '-- none --', + 'Mysqli' => 'MySQL', + 'Sqlsrv' => 'SQL Server'); + } } /** Modified: branches/newUser/classes/Gems/Util/DatabasePatcher.php =================================================================== --- branches/newUser/classes/Gems/Util/DatabasePatcher.php 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/classes/Gems/Util/DatabasePatcher.php 2011-10-21 12:29:37 UTC (rev 124) @@ -1,43 +1,47 @@ <?php - -/** - * Copyright (c) 2011, Erasmus MC - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Erasmus MC nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * @version $Id$ + +/** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * * @package Gems * @subpackage Util + * @author Matijs de Jong <mj...@ma...> * @copyright Copyright (c) 2011 Erasmus MC * @license New BSD License + * @version $Id$ */ /** + * File for checking and executing (new) patches. + * * @package Gems * @subpackage Util * @copyright Copyright (c) 2011 Erasmus MC * @license New BSD License + * @since Class available since version 1.1 */ class Gems_Util_DatabasePatcher { @@ -175,6 +179,22 @@ return $executed; } + /** + * New installations should not be trequired to run patches. This esthablishes that level. + * + * @return int The lowest level of patch stored in the database. + */ + protected function getMinimumPatchLevel() + { + static $level; + + if (! $level) { + $level = intval($this->db->fetchOne("SELECT COALESCE(MIN(gpl_level), 1) FROM gems__patch_levels")); + } + + return $level; + } + public function hasPatchFiles() { return (boolean) $this->patch_files; @@ -195,33 +215,36 @@ $tree = MUtil_Ra_Nested::toTree($existing, 'gpa_level', 'gpa_location', 'gpa_name', 'gpa_order'); $changed = 0; $current = new Zend_Db_Expr('CURRENT_TIMESTAMP'); + $minimum = $this->getMinimumPatchLevel(); + // MUtil_Echo::track($minimum); $this->_loadPatches($applicationLevel); foreach ($this->_loaded_patches as $patch) { + if ($minimum <= $patch['gpa_level']) { + $level = $patch['gpa_level']; + $location = $patch['gpa_location']; + $name = $patch['gpa_name']; + $order = $patch['gpa_order']; - $level = $patch['gpa_level']; - $location = $patch['gpa_location']; - $name = $patch['gpa_name']; - $order = $patch['gpa_order']; + // Does it exist? + if (isset($tree[$level][$location][$name][$order])) { + $sql = $patch['gpa_sql']; + if ($sql != $tree[$level][$location][$name][$order]['gpa_sql']) { + $values['gpa_sql'] = $sql; + $values['gpa_executed'] = 0; + $values['gpa_completed'] = 0; + $values['gpa_changed'] = $current; - // Does it exist? - if (isset($tree[$level][$location][$name][$order])) { - $sql = $patch['gpa_sql']; - if ($sql != $tree[$level][$location][$name][$order]['gpa_sql']) { - $values['gpa_sql'] = $sql; - $values['gpa_executed'] = 0; - $values['gpa_completed'] = 0; - $values['gpa_changed'] = $current; + $this->db->update('gems__patches', $values, $this->db->quoteInto('gpa_id_patch = ?', $tree[$level][$location][$name][$order]['gpa_id_patch'])); + $changed++; + } - $this->db->update('gems__patches', $values, $this->db->quoteInto('gpa_id_patch = ?', $tree[$level][$location][$name][$order]['gpa_id_patch'])); + } else { + $patch['gpa_changed'] = $current; + $patch['gpa_created'] = $current; + $this->db->insert('gems__patches', $patch); $changed++; } - - } else { - $patch['gpa_changed'] = $current; - $patch['gpa_created'] = $current; - $this->db->insert('gems__patches', $patch); - $changed++; } } // */ Modified: branches/newUser/classes/GemsEscort.php =================================================================== --- branches/newUser/classes/GemsEscort.php 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/classes/GemsEscort.php 2011-10-21 12:29:37 UTC (rev 124) @@ -1133,6 +1133,15 @@ } /** + * + * @return string Name of the file that performs the maintenance lock + */ + public function getMaintenanceLockFilename() + { + return GEMS_ROOT_DIR . '/var/settings/lock.txt'; + } + + /** * Retrieve the GemsEscort object * * @return GemsEscort @@ -1523,7 +1532,7 @@ * Check if we are in maintenance mode or not. This is triggeren by a file in the var/settings * directory with the name lock.txt */ - if(file_exists(GEMS_ROOT_DIR . '/var/settings/lock.txt')) { + if (file_exists($this->getMaintenanceLockFilename())) { if ($this->session->user_id && $this->session->user_role !== 'super') { //Still allow logoff so we can relogin as super if (!('index' == $request->getControllerName() && 'logoff' == $request->getActionName())) { @@ -1533,7 +1542,7 @@ $this->_('System is in maintenance mode')); } } else { - $this->getMessenger()->addMessage($this->_('System is in maintenance mode')); + $this->addMessage($this->_('System is in maintenance mode')); MUtil_Echo::r($this->_('System is in maintenance mode')); } } @@ -1598,7 +1607,7 @@ } if (isset($menuItem)) { - $menuItem->applyHiddenParameters($this->menu->getParameterSource()); + $menuItem->applyHiddenParameters($request, $this->menu->getParameterSource()); $this->menu->setCurrent($menuItem); } } Modified: branches/newUser/classes/MUtil/Controller/ModelSnippetActionAbstract.php =================================================================== --- branches/newUser/classes/MUtil/Controller/ModelSnippetActionAbstract.php 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/classes/MUtil/Controller/ModelSnippetActionAbstract.php 2011-10-21 12:29:37 UTC (rev 124) @@ -98,6 +98,19 @@ protected $showSnippets = 'ModelVerticalTableSnippet'; /** + * Array of the actions that use a summarized version of the model. + * + * This determines the value of $detailed in createAction(). As it is usually + * less of a problem to use a $detailed model with an action that should use + * a summarized model and I guess there will usually be more detailed actions + * than summarized ones it seems less work to specify these. + * + * @var array $summarizedActions Array of the actions that use a + * summarized version of the model. + */ + public $summarizedActions = array('index', 'autofilter'); + + /** * Set the action key in request * * Use this when an action is a Ajax action for retrieving @@ -137,7 +150,9 @@ } if ($resetMvc && MUtil_Echo::hasOutput()) { - $this->html->raw(MUtil_Echo::out()); + // Lazy call here, because any echo calls in the snippets have not yet been + // performed. so they will appear only in the next call when not lazy. + $this->html->raw(MUtil_Lazy::call(array('MUtil_Echo', 'out'))); } } Modified: branches/newUser/classes/MUtil/Snippets/ModelTableSnippetAbstract.php =================================================================== --- branches/newUser/classes/MUtil/Snippets/ModelTableSnippetAbstract.php 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/classes/MUtil/Snippets/ModelTableSnippetAbstract.php 2011-10-21 12:29:37 UTC (rev 124) @@ -57,13 +57,6 @@ protected $_marker; /** - * Functional extension: optionally use this function to add the browse columns - * - * @var callable With signature: function(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model, MUtil_Snippets_ModelTableSnippetAbstract $snippet) - */ - public $addTableColumns; - - /** * Url parts added to each link in the resulting table * * @var array @@ -171,11 +164,7 @@ $bridge->setBaseUrl($this->baseUrl); } - if (is_callable($this->addTableColumns)) { - call_user_func($this->addTableColumns, $bridge, $model, $this); - } else { - $this->addBrowseTableColumns($bridge, $model); - } + $this->addBrowseTableColumns($bridge, $model); return $bridge->getTable(); } Modified: branches/newUser/configs/db/patches.sql =================================================================== --- branches/newUser/configs/db/patches.sql 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/configs/db/patches.sql 2011-10-21 12:29:37 UTC (rev 124) @@ -1,4 +1,8 @@ +-- GEMS VERSION: 1 +-- PATCH: Test skip earlier patch levels +SELECT NULL; + -- GEMS VERSION: 27 -- PATCH: Use OK reception code @@ -204,6 +208,10 @@ UPDATE gems__roles SET grl_privileges = CONCAT(grl_privileges,',pr.maintenance') WHERE grl_name = 'super' AND grl_privileges NOT LIKE '%pr.maintenance%'; -- GEMS VERSION: 42 +-- PATCH: Add mail actions to admin role +UPDATE gems__roles SET grl_privileges = CONCAT(grl_privileges, ',pr.mail.log') WHERE grl_name = 'admin' AND grl_privileges NOT LIKE '%pr.mail.log%'; +UPDATE gems__roles SET grl_privileges = CONCAT(grl_privileges, ',pr.mail.server,pr.mail.server.create,pr.mail.server.delete,pr.mail.server.edit') WHERE grl_name = 'super' AND grl_privileges NOT LIKE '%pr.mail.server%'; + -- PATCH: New user login structure INSERT INTO gems__users (gsu_id_user, gsu_login, gsu_id_organization, gsu_user_class, gsu_active, gsu_password, gsu_failed_logins, gsu_last_failed, gsu_reset_key, gsu_reset_requested, gsu_reset_required, @@ -213,4 +221,4 @@ gr2o_changed, gr2o_changed_by, gr2o_created, gr2o_created_by FROM gems__respondents INNER JOIN gems__respondent2org ON grs_id_user = gr2o_id_user INNER JOIN gems__organizations ON gr2o_id_organization = gor_id_organization - WHERE gor_name = 'HCU / Xpert Clinic'; + WHERE gor_name = 'HCU / Xpert Clinic'; \ No newline at end of file Modified: branches/newUser/configs/db/tables/gems__mail_jobs.300.sql =================================================================== --- branches/newUser/configs/db/tables/gems__mail_jobs.300.sql 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/configs/db/tables/gems__mail_jobs.300.sql 2011-10-21 12:29:37 UTC (rev 124) @@ -4,8 +4,6 @@ gmj_id_organization bigint unsigned not null references gems__organizations (gor_id_organization), - gmj_id_message bigint unsigned not null - references gems__mail_templates (gmt_id_message), gmj_id_user_as bigint unsigned not null references gems__staff (gsf_id_user), Modified: branches/newUser/configs/db/tables/gems__reception_codes.10.sql =================================================================== --- branches/newUser/configs/db/tables/gems__reception_codes.10.sql 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/configs/db/tables/gems__reception_codes.10.sql 2011-10-21 12:29:37 UTC (rev 124) @@ -29,5 +29,5 @@ grc_changed, grc_changed_by, grc_created, grc_created_by) VALUES ('OK', '', 1, 1, 0, 1, 1, 1, CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1), - ('skip', 'Skipped by calculation', 0, 1, 0, 0, 0, 0, 0, CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1); + ('skip', 'Skipped by calculation', 0, 1, 0, 0, 0, 0, CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1); Modified: branches/newUser/configs/db/tables/gems__roles.20.sql =================================================================== --- branches/newUser/configs/db/tables/gems__roles.20.sql 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/configs/db/tables/gems__roles.20.sql 2011-10-21 12:29:37 UTC (rev 124) @@ -32,5 +32,5 @@ ('staff','staff','pr.option.edit,pr.option.password,pr.plan,pr.plan.overview,pr.plan.token,pr.project,pr.project.questions,pr.respondent.create,pr.respondent.edit,pr.respondent.who,pr.setup,pr.staff,pr.survey,pr.survey.create,pr.token,pr.token.answers,pr.token.delete,pr.token.edit,pr.token.mail,pr.token.print,pr.track,pr.track.create,pr.track.delete,pr.track.edit,pr.respondent.reportdeath','guest', CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1), ('physician','physician','','staff', CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1), ('researcher','researcher','pr.invitation,pr.result,pr.islogin','', CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1), - ('admin','admin','pr.consent,pr.consent.create,pr.consent.edit,pr.group,pr.role,pr.mail,pr.mail.create,pr.mail.delete,pr.mail.edit,pr.organization,pr.organization-switch,pr.plan.overview.excel,pr.plan.respondent,pr.plan.respondent.excel,pr.plan.token.excel,pr.project-information,pr.reception,pr.reception.create,pr.reception.edit,pr.respondent.choose-org,pr.respondent.delete,pr.respondent.result,pr.source,pr.staff.create,pr.staff.delete,pr.staff.edit,pr.staff.see.all,pr.survey-maintenance,pr.track-maintenance,pr.token.mail.freetext','staff,researcher,security', CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1), - ('super','super','pr.consent.delete,pr.country,pr.country.create,pr.country.delete,pr.country.edit,pr.database,pr.database.create,pr.database.delete,pr.database.edit,pr.database.execute,pr.database.patches,pr.group.create,pr.group.edit,pr.role.create,pr.role.edit,pr.language,pr.organization.create,pr.organization.edit,pr.plan.choose-org,pr.plan.mail-as-application,pr.reception.delete,pr.source.create,pr.source.edit,pr.source.synchronize,pr.source.synchronize-all,pr.staff.edit.all,pr.survey-maintenance.edit,pr.track-maintenance.create,pr.track-maintenance.edit,pr.maintenance','admin', CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1); + ('admin','admin','pr.consent,pr.consent.create,pr.consent.edit,pr.group,pr.role,pr.mail,pr.mail.create,pr.mail.delete,pr.mail.edit,pr.mail.log,pr.organization,pr.organization-switch,pr.plan.overview.excel,pr.plan.respondent,pr.plan.respondent.excel,pr.plan.token.excel,pr.project-information,pr.reception,pr.reception.create,pr.reception.edit,pr.respondent.choose-org,pr.respondent.delete,pr.respondent.result,pr.source,pr.staff.create,pr.staff.delete,pr.staff.edit,pr.staff.see.all,pr.survey-maintenance,pr.track-maintenance,pr.token.mail.freetext','staff,researcher,security', CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1), + ('super','super','pr.consent.delete,pr.country,pr.country.create,pr.country.delete,pr.country.edit,pr.database,pr.database.create,pr.database.delete,pr.database.edit,pr.database.execute,pr.database.patches,pr.group.create,pr.group.edit,pr.language,pr.mail.server,pr.mail.server.create,pr.mail.server.delete,pr.mail.server.edit,pr.organization.create,pr.organization.edit,pr.plan.choose-org,pr.plan.mail-as-application,pr.reception.delete,pr.role.create,pr.role.edit,pr.source.create,pr.source.edit,pr.source.synchronize,pr.source.synchronize-all,pr.staff.edit.all,pr.survey-maintenance.edit,pr.track-maintenance.create,pr.track-maintenance.edit,pr.maintenance','admin', CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1); Modified: branches/newUser/configs/db/tables/gems__surveys.30.sql =================================================================== --- branches/newUser/configs/db/tables/gems__surveys.30.sql 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/configs/db/tables/gems__surveys.30.sql 2011-10-21 12:29:37 UTC (rev 124) @@ -20,7 +20,10 @@ references gems__sources (gso_id_source), gsu_active boolean not null default 0, gsu_status varchar(127) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci', + + -- depreciated gsu_staff boolean not null default 0, + -- end depreciated gsu_id_primary_group bigint unsigned null references gems__groups (ggp_id_group), Modified: branches/newUser/controllers/MailLogController.php =================================================================== --- branches/newUser/controllers/MailLogController.php 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/controllers/MailLogController.php 2011-10-21 12:29:37 UTC (rev 124) @@ -42,6 +42,5 @@ * @license New BSD License * @since Class available since version 1.4.2 */ -class MailLogController extends Gems_Default_MailLogActionOldStyle -{ -} +class MailLogController extends Gems_Default_MailLogAction +{ } Modified: branches/newUser/languages/default-en.mo =================================================================== (Binary files differ) Modified: branches/newUser/languages/default-en.po =================================================================== --- branches/newUser/languages/default-en.po 2011-10-21 12:15:43 UTC (rev 123) +++ branches/newUser/languages/default-en.po 2011-10-21 12:29:37 UTC (rev 124) @@ -2,9 +2,9 @@ msgstr "" "Project-Id-Version: Pulse EN\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-10-17 15:19+0100\n" +"POT-Creation-Date: 2011-10-20 17:52+0100\n" "PO-Revision-Date: \n" -"Last-Translator: Menno Dekker <men...@er...>\n" +"Last-Translator: Matijs de Jong <mj...@ma...>\n" "Language-Team: Erasmus MGZ <mat...@ma...>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -32,44 +32,44 @@ msgid "version" msgstr "version" -#: classes/GemsEscort.php:1410 +#: classes/GemsEscort.php:1419 msgid "Take note: your session has expired, your inputs where not saved. Please check the input data and try again" msgstr "Take note: your session has expired, your inputs where not saved. Please check the input data and try again" -#: classes/GemsEscort.php:1531 +#: classes/GemsEscort.php:1540 msgid "Please check back later." msgstr "Please check back later." -#: classes/GemsEscort.php:1533 -#: classes/GemsEscort.php:1536 -#: classes/GemsEscort.php:1537 +#: classes/GemsEscort.php:1542 +#: classes/GemsEscort.php:1545 +#: classes/GemsEscort.php:1546 msgid "System is in maintenance mode" msgstr "System is in maintenance mode" -#: classes/GemsEscort.php:1551 +#: classes/GemsEscort.php:1560 msgid "No access to site." msgstr "No access to site." -#: classes/GemsEscort.php:1553 -#: classes/GemsEscort.php:1589 +#: classes/GemsEscort.php:1562 +#: classes/GemsEscort.php:1598 msgid "You have no access to this site." msgstr "You have no access to this site." -#: classes/GemsEscort.php:1569 +#: classes/GemsEscort.php:1578 msgid "No access to page" msgstr "No access to page" -#: classes/GemsEscort.php:1571 +#: classes/GemsEscort.php:1580 #, php-format msgid "Access to this page is not allowed for current role: %s." msgstr "Access to this page is not allowed for current role: %s." -#: classes/GemsEscort.php:1576 -#: classes/GemsEscort.php:1587 +#: classes/GemsEscort.php:1585 +#: classes/GemsEscort.php:1596 msgid "You are no longer logged in." msgstr "You are no longer logged in." -#: classes/GemsEscort.php:1577 +#: classes/GemsEscort.php:1586 msgid "You must login to access this page." msgstr "You must login to access this page." @@ -381,7 +381,7 @@ msgid "Birthday" msgstr "Birthday" -#: classes/Gems/Tracker.php:726 +#: classes/Gems/Tracker.php:732 msgid "Checks performed" msgstr "Checks performed" @@ -1151,8 +1151,7 @@ msgstr "Log maintenance" #: classes/Gems/Default/MailAction.php:61 -#: classes/Gems/Default/MailLogAction.php:132 -#: classes/Gems/Default/MailLogActionOldStyle.php:118 +#: classes/Gems/Default/MailLogAction.php:113 msgid "Subject" msgstr "Subject" @@ -1170,51 +1169,38 @@ msgid "Email templates" msgstr "Email templates" -#: classes/Gems/Default/MailLogAction.php:126 -#: classes/Gems/Default/MailLogActionOldStyle.php:112 +#: classes/Gems/Default/MailLogAction.php:107 msgid "Date sent" msgstr "Date sent" -#: classes/Gems/Default/MailLogAction.php:127 -#: classes/Gems/Default/MailLogActionOldStyle.php:113 +#: classes/Gems/Default/MailLogAction.php:108 msgid "Receiver" msgstr "Receiver" -#: classes/Gems/Default/MailLogAction.php:128 -#: classes/Gems/Default/MailLogActionOldStyle.php:114 +#: classes/Gems/Default/MailLogAction.php:109 msgid "To address" msgstr "To address" -#: classes/Gems/Default/MailLogAction.php:129 -#: classes/Gems/Default/MailLogActionOldStyle.php:115 +#: classes/Gems/Default/MailLogAction.php:110 msgid "Sender" msgstr "Sender" -#: classes/Gems/Default/MailLogAction.php:130 -#: classes/Gems/Default/MailLogActionOldStyle.php:116 +#: classes/Gems/Default/MailLogAction.php:111 msgid "From address" msgstr "From address" -#: classes/Gems/Default/MailLogAction.php:135 -#: classes/Gems/Default/MailLogActionOldStyle.php:121 +#: classes/Gems/Default/MailLogAction.php:116 msgid "Template" msgstr "Template" -#: classes/Gems/Default/MailLogAction.php:148 -#: classes/Gems/Default/MailLogActionOldStyle.php:148 +#: classes/Gems/Default/MailLogAction.php:129 msgid "Mail Activity Log" msgstr "Mail Activity Log" -#: classes/Gems/Default/MailLogAction.php:160 +#: classes/Gems/Default/MailLogAction.php:140 msgid "Show Mail Activity Log item" msgstr "Show Mail Activity Log item" -#: classes/Gems/Default/MailLogActionOldStyle.php:137 -msgid "Activity Log" -msgid_plural "Activity Logs" -msgstr[0] "Activity Log" -msgstr[1] "Activity Logs" - #: classes/Gems/Default/MailServerAction.php:68 msgid "From address [part]" msgstr "From address [part]" @@ -1256,6 +1242,8 @@ msgstr "User ID" #: classes/Gems/Default/MailServerAction.php:90 +#: classes/Gems/Default/OptionAction.php:107 +#: classes/Gems/Default/OptionAction.php:112 msgid "Repeat password" msgstr "Repeat password" @@ -1274,14 +1262,10 @@ msgstr "Email servers" #: classes/Gems/Default/OptionAction.php:73 -#: classes/Gems/Default/OrganizationAction.php:128 -#: classes/Gems/Default/RespondentAction.php:173 -#: classes/Gems/Default/StaffAction.php:188 msgid "Language" msgstr "Language" #: classes/Gems/Default/OptionAction.php:74 -#: classes/Gems/Default/StaffAction.php:189 msgid "Logout on survey" msgstr "Logout on survey" @@ -1346,7 +1330,6 @@ msgstr "Invalid organization." #: classes/Gems/Default/OrganizationAction.php:117 -#: classes/Gems/Default/SourceAction.php:143 msgid "Url" msgstr "Url" @@ -1402,107 +1385,115 @@ msgid "Planning overview" msgstr "Planning overview" -#: classes/Gems/Default/ProjectInformationAction.php:71 +#: classes/Gems/Default/ProjectInformationAction.php:83 msgid "empty file" msgstr "empty file" -#: classes/Gems/Default/ProjectInformationAction.php:75 +#: classes/Gems/Default/ProjectInformationAction.php:87 msgid "file not found" msgstr "file not found" -#: classes/Gems/Default/ProjectInformationAction.php:108 +#: classes/Gems/Default/ProjectInformationAction.php:120 msgid "Logged errors" msgstr "Logged errors" -#: classes/Gems/Default/ProjectInformationAction.php:108 +#: classes/Gems/Default/ProjectInformationAction.php:120 msgid "Empty logfile" msgstr "Empty logfile" -#: classes/Gems/Default/ProjectInformationAction.php:113 +#: classes/Gems/Default/ProjectInformationAction.php:125 msgid "Project information" msgstr "Project information" -#: classes/Gems/Default/ProjectInformationAction.php:117 +#: classes/Gems/Default/ProjectInformationAction.php:129 msgid "Project name" msgstr "Project name" -#: classes/Gems/Default/ProjectInformationAction.php:118 +#: classes/Gems/Default/ProjectInformationAction.php:130 msgid "Project version" msgstr "Project version" -#: classes/Gems/Default/ProjectInformationAction.php:119 +#: classes/Gems/Default/ProjectInformationAction.php:131 msgid "Gems version" msgstr "Gems version" -#: classes/Gems/Default/ProjectInformationAction.php:121 +#: classes/Gems/Default/ProjectInformationAction.php:133 msgid "Gems project" msgstr "Gems project" -#: classes/Gems/Default/ProjectInformationAction.php:122 +#: classes/Gems/Default/ProjectInformationAction.php:134 msgid "Gems web directory" msgstr "Gems web directory" -#: classes/Gems/Default/ProjectInformationAction.php:123 +#: classes/Gems/Default/ProjectInformationAction.php:135 msgid "Gems code directory" msgstr "Gems code directory" -#: classes/Gems/Default/ProjectInformationAction.php:124 +#: classes/Gems/Default/ProjectInformationAction.php:136 msgid "Gems project path" msgstr "Gems project path" -#: classes/Gems/Default/ProjectInformationAction.php:125 +#: classes/Gems/Default/ProjectInformationAction.php:137 msgid "MUtil version" msgstr "MUtil version" -#: classes/Gems/Default/ProjectInformationAction.php:126 +#: classes/Gems/Default/ProjectInformationAction.php:138 msgid "Zend version" msgstr "Zend version" -#: classes/Gems/Default/ProjectInformationAction.php:127 +#: classes/Gems/Default/ProjectInformationAction.php:139 msgid "Application environment" msgstr "Application environment" -#: classes/Gems/Default/ProjectInformationAction.php:128 +#: classes/Gems/Default/ProjectInformationAction.php:140 msgid "Application baseuri" msgstr "Application baseuri" -#: classes/Gems/Default/ProjectInformationAction.php:129 +#: classes/Gems/Default/ProjectInformationAction.php:141 msgid "Application directory" msgstr "Application directory" -#: classes/Gems/Default/ProjectInformationAction.php:130 +#: classes/Gems/Default/ProjectInformationAction.php:142 msgid "PHP version" msgstr "PHP version" -#: classes/Gems/Default/ProjectInformationAction.php:131 +#: classes/Gems/Default/ProjectInformationAction.php:143 msgid "Server Hostname" msgstr "Server Hostname" -#: classes/Gems/Default/ProjectInformationAction.php:132 +#: classes/Gems/Default/ProjectInformationAction.php:144 msgid "Server OS" msgstr "Server OS" -#: classes/Gems/Default/ProjectInformationAction.php:133 +#: classes/Gems/Default/ProjectInformationAction.php:145 msgid "Time on server" msgstr "Time on server" -#: classes/Gems/Default/ProjectInformationAction.php:135 +#: classes/Gems/Default/ProjectInformationAction.php:148 +msgid "Turn Maintenance Mode OFF" +msgstr "Turn Maintenance Mode OFF" + +#: classes/Gems/Default/ProjectInformationAction.php:150 +msgid "Turn Maintenance Mode ON" +msgstr "Turn Maintenance Mode ON" + +#: classes/Gems/Default/ProjectInformationAction.php:159 msgid "Version information" msgstr "Version information" -#: classes/Gems/Default/ProjectInformationAction.php:151 +#: classes/Gems/Default/ProjectInformationAction.php:185 msgid "Server PHP Info" msgstr "Server PHP Info" -#: classes/Gems/Default/ProjectInformationAction.php:164 +#: classes/Gems/Default/ProjectInformationAction.php:198 msgid "Project settings" msgstr "Project settings" -#: classes/Gems/Default/ProjectInformationAction.php:171 +#: classes/Gems/Default/ProjectInformationAction.php:205 msgid "Session content" msgstr "Session content" -#: classes/Gems/Default/ProjectInformationAction.php:172 +#: classes/Gems/Default/ProjectInformationAction.php:206 msgid "Session" msgstr "Session" @@ -1561,6 +1552,7 @@ msgstr "Survey not specified." #: classes/Gems/Default/ProjectTracksAction.php:120 +#: classes/Gems/Default/TrackActionAbstract.php:479 #, php-format msgid "Track %s does not exist." msgstr "Track %s does not exist." @@ -1791,6 +1783,18 @@ msgid "Leave empty for the Gems database." msgstr "Leave empty for the Gems database." +#: classes/Gems/Default/SourceAction.php:79 +msgid "E.g. the name of the project - for single source projects." +msgstr "E.g. the name of the project - for single source projects." + +#: classes/Gems/Default/SourceAction.php:81 +msgid "For creating token-survey url." +msgstr "For creating token-survey url." + +#: classes/Gems/Default/SourceAction.php:86 +msgid "The database server used by the source." +msgstr "The database server used by the source." + #: classes/Gems/Default/SourceAction.php:88 msgid "Do not forget the underscores." msgstr "Do not forget the underscores." @@ -1808,63 +1812,67 @@ msgid "Checking survey results for %s source." msgstr "Checking survey res... [truncated message content] |
From: <gem...@li...> - 2011-10-25 15:58:11
|
Revision: 140 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=140&view=rev Author: matijsdejong Date: 2011-10-25 15:58:01 +0000 (Tue, 25 Oct 2011) Log Message: ----------- Brought up to date with revisions up to 139 Modified Paths: -------------- branches/newUser/changelog.txt branches/newUser/classes/Gems/Controller/ModelSnippetActionAbstract.php branches/newUser/classes/Gems/Default/DatabaseAction.php branches/newUser/classes/Gems/Default/IndexAction.php branches/newUser/classes/Gems/Default/MailLogAction.php branches/newUser/classes/Gems/Default/ProjectInformationAction.php branches/newUser/classes/Gems/Default/RoleAction.php branches/newUser/classes/Gems/Default/StaffAction.php branches/newUser/classes/Gems/Email/EmailFormAbstract.php branches/newUser/classes/Gems/Email/MultiMailForm.php branches/newUser/classes/Gems/Email/TemplateMailer.php branches/newUser/classes/Gems/Menu/MenuAbstract.php branches/newUser/classes/Gems/Menu.php branches/newUser/classes/Gems/Roles.php branches/newUser/classes/Gems/Snippets/ModelFormSnippetAbstract.php branches/newUser/classes/Gems/Snippets/ModelTableSnippetAbstract.php branches/newUser/classes/Gems/Tracker/Engine/StepEngineAbstract.php branches/newUser/classes/Gems/Tracker/Source/LimeSurvey1m9FieldMap.php branches/newUser/classes/Gems/Util/DbLookup.php branches/newUser/classes/Gems/Util/Translated.php branches/newUser/classes/Gems/Util.php branches/newUser/classes/GemsEscort.php branches/newUser/classes/MUtil/Controller/ModelSnippetActionAbstract.php branches/newUser/classes/MUtil/Snippets/ModelFormSnippetAbstract.php branches/newUser/classes/MUtil/Snippets/ModelVerticalTableSnippetAbstract.php branches/newUser/classes/MUtil/Snippets/Standard/ModelVerticalTableSnippet.php branches/newUser/configs/db/patches.sql branches/newUser/configs/db/tables/gems__mail_jobs.300.sql branches/newUser/controllers/EmailController.php branches/newUser/languages/default-en.mo branches/newUser/languages/default-en.po branches/newUser/languages/default-nl.mo branches/newUser/languages/default-nl.po branches/newUser/snippets/Generic/ModelItemTableSnippet.php branches/newUser/snippets/Mail/Log/MailLogBrowseSnippet.php Added Paths: ----------- branches/newUser/classes/Gems/Default/CronAction.php branches/newUser/classes/Gems/Default/MailJobAction.php branches/newUser/classes/Gems/Default/MailTemplateAction.php branches/newUser/classes/Gems/Snippets/ModelFormSnippetGeneric.php branches/newUser/classes/Gems/Snippets/ModelItemTableSnippetAbstract.php branches/newUser/classes/Gems/Snippets/ModelItemTableSnippetGeneric.php branches/newUser/classes/Gems/Snippets/ModelItemYesNoDeleteSnippetAbstract.php branches/newUser/classes/Gems/Snippets/ModelItemYesNoDeleteSnippetGeneric.php branches/newUser/classes/Gems/Util/LockFile.php branches/newUser/classes/MUtil/Mail/ branches/newUser/classes/MUtil/Mail/Transport/ branches/newUser/classes/MUtil/Mail/Transport/EchoLog.php branches/newUser/classes/MUtil/Snippets/ModelYesNoDeleteSnippetAbstract.php branches/newUser/classes/MUtil/Snippets/Standard/ModelYesNoDeleteSnippet.php branches/newUser/controllers/CronController.php branches/newUser/controllers/MailJobController.php branches/newUser/controllers/MailTemplateController.php branches/newUser/snippets/Generic/ModelFormSnippet.php branches/newUser/snippets/Generic/ModelItemYesNoDeleteSnippet.php Removed Paths: ------------- branches/newUser/classes/Gems/Default/EmailAction.php branches/newUser/classes/Gems/Default/MailAction.php branches/newUser/classes/MUtil/Mail/Transport/ branches/newUser/classes/MUtil/Mail/Transport/EchoLog.php branches/newUser/controllers/MailController.php Property Changed: ---------------- branches/newUser/ Property changes on: branches/newUser ___________________________________________________________________ Modified: svn:mergeinfo - /trunk/library:114-122 + /trunk/library:114-122,125-139 Modified: branches/newUser/changelog.txt =================================================================== --- branches/newUser/changelog.txt 2011-10-25 15:34:11 UTC (rev 139) +++ branches/newUser/changelog.txt 2011-10-25 15:58:01 UTC (rev 140) @@ -1,3 +1,8 @@ +Important changes from 1.4.3 => 1.5 +============================================================ +MailController is now called MailTemplateController +EmailController is now called CronController (with stub for compatibility) + Important changes from 1.4.2 => 1.4.3 ============================================================ * gtr_organisations renamed to gtr_organizations Modified: branches/newUser/classes/Gems/Controller/ModelSnippetActionAbstract.php =================================================================== --- branches/newUser/classes/Gems/Controller/ModelSnippetActionAbstract.php 2011-10-25 15:34:11 UTC (rev 139) +++ branches/newUser/classes/Gems/Controller/ModelSnippetActionAbstract.php 2011-10-25 15:58:01 UTC (rev 140) @@ -26,7 +26,6 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * Short description of file * * @package Gems * @subpackage Controller @@ -37,10 +36,8 @@ */ /** - * Short description for class + * Class contains Gems specific adaptations to parent class. * - * Long description for class (if any)... - * * @package Gems * @subpackage Controller * @copyright Copyright (c) 2011 Erasmus MC @@ -50,12 +47,6 @@ abstract class Gems_Controller_ModelSnippetActionAbstract extends MUtil_Controller_ModelSnippetActionAbstract { /** - * - * @var GemsEscort - */ - public $escort; - - /** * The parameters used for the autofilter action. * * @var array Mixed key => value array for snippet initialization @@ -74,6 +65,32 @@ protected $autofilterSnippets = 'Generic_ModelTableSnippet'; /** + * The snippets used for the create and edit actions. + * + * @var mixed String or array of snippets name + */ + protected $createEditSnippets = 'Generic_ModelFormSnippet'; + + /** + * The snippets used for the delete action. + * + * @var mixed String or array of snippets name + */ + protected $deleteSnippets = 'Generic_ModelItemYesNoDeleteSnippet'; + + /** + * + * @var GemsEscort + */ + public $escort; + + /** + * + * @var Gems_Menu + */ + public $menu; + + /** * The snippets used for the index action, before those in autofilter * * @var mixed String or array of snippets name Copied: branches/newUser/classes/Gems/Default/CronAction.php (from rev 139, trunk/library/classes/Gems/Default/CronAction.php) =================================================================== --- branches/newUser/classes/Gems/Default/CronAction.php (rev 0) +++ branches/newUser/classes/Gems/Default/CronAction.php 2011-10-25 15:58:01 UTC (rev 140) @@ -0,0 +1,252 @@ +<?php + +/** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * @author Michiel Rook <mi...@to...> + * @package Gems + * @subpackage Default + */ + +/** + * Performs bulk-mail action, can be called from a cronjob + * + * @author Michiel Rook <mi...@to...> + * @package Gems + * @subpackage Default + */ +class Gems_Default_CronAction extends MUtil_Controller_Action +{ + /** + * + * @var Zend_Db_Adapter_Abstract + */ + public $db; + + /** + * Standard filter that must be true for every token query. + * + * @var array + */ + protected $defaultFilter = array( + 'can_email' => 1, + 'gtr_active' => 1, + 'gsu_active' => 1, + 'grc_success' => 1, + 'gto_completion_time' => NULL, + 'gto_valid_from <= CURRENT_DATE', + '(gto_valid_until IS NULL OR gto_valid_until >= CURRENT_TIMESTAMP)' + ); + + /** + * + * @var GemsEscort + */ + public $escort; + + /** + * + * @var Gems_Menu + */ + public $menu; + + /** + * + * @var Zend_Session_Namespace + */ + public $session; + + /** + * Set to true in child class for automatic creation of $this->html. + * + * Otherwise call $this->initHtml() + * + * @var boolean $useHtmlView + */ + public $useHtmlView = true; + + /** + * + * @var Gems_Util + */ + public $util; + + /** + * Action that switches the cron job lock on or off. + */ + public function cronLockAction() + { + // Switch lock + $this->util->getCronJobLock()->reverse(); + + // Redirect + $request = $this->getRequest(); + $this->_reroute($this->menu->getCurrentParent()->toRouteUrl()); + } + + /** + * Loads an e-mail template + * + * @param integer|null $templateId + */ + protected function getTemplate($templateId) + { + return $this->db->fetchRow('SELECT * FROM gems__mail_templates WHERE gmt_id_message = ?', $templateId); + } + + /** + * Returns the login name belonging to this user. + * + * @param int $userId + * @return string + */ + protected function getUserLogin($userId) + { + return $this->db->fetchOne("SELECT gsf_login FROM gems__staff WHERE gsf_id_user = ?", $userId); + } + + public function indexAction() + { + $this->initHtml(); + + if ($this->util->getCronJobLock()->isLocked()) { + $this->html->append($this->_('Cron jobs turned off.')); + } else { + $this->mailJob(); + } + } + + public function mailJob() + { + // Test: update `gems__tokens` set `gto_mail_sent_date` = null where `gto_mail_sent_date` > '2011-10-23' + + $currentUser = isset($this->session->user_login) ? $this->session->user_login : null; + + $model = $this->loader->getTracker()->getTokenModel(); + $mailer = new Gems_Email_TemplateMailer($this->escort); + // $mailer->setDefaultTransport(new MUtil_Mail_Transport_EchoLog()); + + $jobs = $this->db->fetchAll("SELECT * FROM gems__mail_jobs WHERE gmj_active = 1"); + + if ($jobs) { + foreach ($jobs as $job) { + $this->escort->loadLoginInfo($this->getUserLogin($job['gmj_id_user_as'])); + + // Set up filter + $filter = $this->defaultFilter; + if ($job['gmj_filter_mode'] == 'R') { + $filter[] = 'gto_mail_sent_date <= DATE_SUB(CURRENT_DATE, INTERVAL ' . $job['gmj_filter_days_between'] . ' DAY)'; + } else { + $filter['gto_mail_sent_date'] = NULL; + } + if ($job['gmj_id_organization']) { + $filter['gto_id_organization'] = $job['gmj_id_organization']; + } + if ($job['gmj_id_track']) { + $filter['gto_id_track'] = $job['gmj_id_track']; + } + if ($job['gmj_id_survey']) { + $filter['gto_id_survey'] = $job['gmj_id_survey']; + } + + $tokensData = $model->load($filter); + + if (count($tokensData)) { + $mailer->setMethod($job['gmj_process_method']); + if ($job['gmj_from_method'] == 'F') { + $mailer->setFrom($job['gmj_from_fixed']); + } else { + $mailer->setFrom($job['gmj_from_method']); + } + + $templateData = $this->getTemplate($job['gmj_id_message']); + $mailer->setSubject($templateData['gmt_subject']); + $mailer->setBody($templateData['gmt_body']); + + $mailer->setTokens(MUtil_Ra::column('gto_id_token', $tokensData)); + $mailer->process($tokensData); + } + + Gems_Auth::getInstance()->clearIdentity(); + $this->escort->session->unsetAll(); + } + } + + $msg = $mailer->getMessages(); + if (! $msg) { + $msg[] = $this->_('No mails sent'); + } + + $this->html->append($msg); + + if ($currentUser) { + $this->escort->loadLoginInfo($currentUser); + } else { + $this->escort->afterLogout(); + } + + /* + if (isset($this->project->email['automatic'])) { + $batches = $this->project->email['automatic']; + $numBatches = count($batches['mode']); + + for ($i = 0; $i < $numBatches; $i++) { + $this->_organizationId = $batches['organization'][$i]; + + if (isset($batches['days'][$i])) { + $this->_intervalDays = $batches['days'][$i]; + } + + $this->escort->loadLoginInfo($batches['user'][$i]); + + $model->setFilter($this->getFilter($batches['mode'][$i])); + + $tokensData = $model->load(); + + if (count($tokensData)) { + $tokens = array(); + + foreach ($tokensData as $tokenData) { + $tokens[] = $tokenData['gto_id_token']; + } + + $templateData = $this->getTemplate($batches['template'][$i]); + $mailer->setSubject($templateData['gmt_subject']); + $mailer->setBody($templateData['gmt_body']); + $mailer->setMethod($batches['method'][$i]); + $mailer->setFrom($batches['from'][$i]); + $mailer->setTokens($tokens); + + $mailer->process($tokensData); + } + + Gems_Auth::getInstance()->clearIdentity(); + $this->escort->session->unsetAll(); + } + } + // */ + } +} \ No newline at end of file Modified: branches/newUser/classes/Gems/Default/DatabaseAction.php =================================================================== --- branches/newUser/classes/Gems/Default/DatabaseAction.php 2011-10-25 15:34:11 UTC (rev 139) +++ branches/newUser/classes/Gems/Default/DatabaseAction.php 2011-10-25 15:58:01 UTC (rev 140) @@ -93,6 +93,18 @@ } /** + * Set the parameters needed by the menu. + * + * @param array $data The current model item + */ + private function _setMenuParameters(array $data) + { + $source = $this->menu->getParameterSource(); + $source['script'] = $data['script'] ? true : false; + $source['exists'] = $data['exists'] ? true : false; + } + + /** * Adds elements from the model to the bridge that creates the form. * * Overrule this function to add different elements to the browse table, without @@ -180,6 +192,8 @@ $model = $this->getModel(); $data = $model->applyRequest($this->getRequest())->loadFirst(); + $this->_setMenuParameters($data); + if (! ($data && isset($data['exists']) && $data['exists'])) { $this->addMessage($this->_('This database object does not exist. You cannot delete it.')); $this->html->buttonDiv($this->createMenuLinks(1)); @@ -438,6 +452,8 @@ $model = $this->getModel(); $data = $model->loadFirst(); + $this->_setMenuParameters($data); + if (! ($data && isset($data['exists'], $data['script']) && ($data['exists'] || $data['script']))) { $this->addMessage($this->_('This database object does not exist. You cannot create it.')); $this->html->buttonDiv($this->createMenuLinks(1)); @@ -580,9 +596,9 @@ $model = $this->getModel(); $data = $model->loadFirst(); - $source = $this->menu->getParameterSource(); - $source['script'] = $data['script']; - $source['exists'] = $data['exists']; + if ($data) { + $this->_setMenuParameters($data); + } parent::showAction(); } @@ -592,6 +608,8 @@ $model = $this->getModel(); $data = $model->loadFirst(); + $this->_setMenuParameters($data); + if (! ($data && isset($data['exists']) && $data['exists'])) { $this->addMessage($this->_('This database object does not exist. You cannot view it.')); $this->html->buttonDiv($this->createMenuLinks(1)); Deleted: branches/newUser/classes/Gems/Default/EmailAction.php =================================================================== --- branches/newUser/classes/Gems/Default/EmailAction.php 2011-10-25 15:34:11 UTC (rev 139) +++ branches/newUser/classes/Gems/Default/EmailAction.php 2011-10-25 15:58:01 UTC (rev 140) @@ -1,135 +0,0 @@ -<?php - -/** - * Copyright (c) 2011, Erasmus MC - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Erasmus MC nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * @author Michiel Rook <mi...@to...> - * @package Gems - * @subpackage Default - */ - -/** - * Performs bulk-mail action, can be called from a cronjob - * - * @author Michiel Rook <mi...@to...> - * @package Gems - * @subpackage Default - */ -class Gems_Default_EmailAction extends Gems_Default_TokenPlanAction -{ - private $_organizationId = null; - private $_intervalDays = 7; - - /** - * Constructs - * @param strings $mode Either 'notmailed' or 'reminder' - */ - protected function getFilter($mode = null) - { - $filter = array( - 'can_email' => 1, - 'gto_id_organization' => $this->_organizationId, - 'gtr_active' => 1, - 'gsu_active' => 1, - 'grc_success' => 1, - 'gto_completion_time' => NULL, - '`gto_valid_from` >= DATE_ADD(CURRENT_DATE, INTERVAL -4 WEEK)', - '`gto_valid_from` <= DATE_ADD(CURRENT_DATE, INTERVAL 2 WEEK)', - '(gto_valid_until IS NULL OR gto_valid_until >= CURRENT_TIMESTAMP)' - ); - - if (isset($mode) && $mode == 'reminder') { - $filter[] = 'gto_mail_sent_date <= DATE_SUB(CURRENT_DATE, INTERVAL ' . $this->_intervalDays . ' DAY)'; - } else { - $filter['gto_mail_sent_date'] = NULL; - } - - return $filter; - } - - /** - * Loads an e-mail template - * @param integer|null $templateId - */ - protected function getTemplate($templateId) - { - $model = new MUtil_Model_TableModel('gems__mail_templates'); - - return $model->loadFirst(array('gmt_id_message' => $templateId)); - } - - public function indexAction() - { - $this->initHtml(); - - $model = $this->loader->getTracker()->getTokenModel(); - $model->setCreate(false); - - $mailer = new Gems_Email_TemplateMailer($this->escort); - - if (isset($this->project->email['automatic'])) { - $batches = $this->project->email['automatic']; - $numBatches = count($batches['mode']); - - for ($i = 0; $i < $numBatches; $i++) { - $this->_organizationId = $batches['organization'][$i]; - - if (isset($batches['days'][$i])) { - $this->_intervalDays = $batches['days'][$i]; - } - - $this->escort->loadLoginInfo($batches['user'][$i]); - - $model->setFilter($this->getFilter($batches['mode'][$i])); - - $tokensData = $model->load(); - - if (count($tokensData)) { - $tokens = array(); - - foreach ($tokensData as $tokenData) { - $tokens[] = $tokenData['gto_id_token']; - } - - $templateData = $this->getTemplate($batches['template'][$i]); - $mailer->setSubject($templateData['gmt_subject']); - $mailer->setBody($templateData['gmt_body']); - $mailer->setMethod($batches['method'][$i]); - $mailer->setFrom($batches['from'][$i]); - $mailer->setTokens($tokens); - - $mailer->process($tokensData); - } - - Gems_Auth::getInstance()->clearIdentity(); - $this->escort->session->unsetAll(); - } - } - - $this->html->append($mailer->getMessages()); - - } -} \ No newline at end of file Modified: branches/newUser/classes/Gems/Default/IndexAction.php =================================================================== --- branches/newUser/classes/Gems/Default/IndexAction.php 2011-10-25 15:34:11 UTC (rev 139) +++ branches/newUser/classes/Gems/Default/IndexAction.php 2011-10-25 15:58:01 UTC (rev 140) @@ -61,6 +61,11 @@ public $escort; /** + * @var Gems_Menu + */ + public $menu; + + /** * Extension point, use different auth adapter if needed depending on the provided formValues * * This could be an organization passed in the login-form or something else. @@ -150,8 +155,17 @@ public function loginAction() { + /** + * If already logged in, try to redirect to the first allowed and visible menu item + * if that fails, try to reroute to respondent/index + */ if (isset($this->session->user_id)) { - $this->_reroute(array('controller' => 'respondent')); + if ($menuItem = $this->menu->findFirst(array('allowed' => true, 'visible' => true))) { + $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); + $redirector->gotoRoute($menuItem->toRouteUrl($this->getRequest())); + } else { + $this->_reroute(array('controller' => 'respondent', 'action'=>'index')); + } } // MUtil_Echo::track(get_class($this->loader->getUser('super', null))); @@ -168,10 +182,10 @@ $this->session->user_id = 2000; $this->session->user_name = $_POST['userlogin']; $this->session->user_group = 800; - $this->session->user_role = 'super'; + $this->session->user_role = 'master'; $this->session->user_organization_id = 70; $this->session->user_organization_name = 'SUPER ADMIN'; - $this->session->user_style = 'pulse'; + $this->session->user_style = 'gems'; //Als er nog geen tabellen zijn, moet dit ingesteld worden //@@TODO Nog kijken hoe beter op te lossen (met try op tabel ofzo) $this->session->allowedOrgs = array($this->session->user_organization_id=>$this->session->user_organization_name); Deleted: branches/newUser/classes/Gems/Default/MailAction.php =================================================================== --- branches/newUser/classes/Gems/Default/MailAction.php 2011-10-25 15:34:11 UTC (rev 139) +++ branches/newUser/classes/Gems/Default/MailAction.php 2011-10-25 15:58:01 UTC (rev 140) @@ -1,130 +0,0 @@ -<?php - -/** - * Copyright (c) 2011, Erasmus MC - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Erasmus MC nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * @package Gems - * @subpackage Default - * @author Matijs de Jong <mj...@ma...> - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @version $Id$ - */ - -/** - * - * @package Gems - * @subpackage Default - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @since Class available since version 1.1 - */ -class Gems_Default_MailAction extends Gems_Controller_BrowseEditAction -{ - /** - * Creates a model for getModel(). Called only for each new $action. - * - * The parameters allow you to easily adapt the model to the current action. The $detailed - * parameter was added, because the most common use of action is a split between detailed - * and summarized actions. - * - * @param boolean $detailed True when the current action is not in $summarizedActions. - * @param string $action The current action. - * $return MUtil_Model_ModelAbstract - */ - public function createModel($detailed, $action) - { - $model = new MUtil_Model_TableModel('gems__mail_templates'); - $model->set('gmt_subject', 'label', $this->_('Subject')); - - if ($detailed) { - $model->set('gmt_body', - 'label', $this->_('Message'), - 'itemDisplay', array('Gems_Email_EmailFormAbstract', 'displayMailText')); - } - - return $model; - } - - public function getAutoSearchElements(MUtil_Model_ModelAbstract $model, array $data) - { - $elements = parent::getAutoSearchElements($model, $data); - $options = array('' => $this->_('(all organizations)')) + $this->util->getDbLookup()->getOrganizations(); - - $elements[] = new Zend_Form_Element_Select('org_id', array('multiOptions' => $options)); - - return $elements; - } - - protected function getDataFilter(array $data) - { - if (isset($data['org_id']) && $data['org_id']) { - $organizationId = intval($data['org_id']); - return array("LOCATE('|$organizationId|', gmt_organizations) > 0"); - } - - return parent::getDataFilter($data); - } - - public function getTopic($count = 1) - { - return $this->plural('email template', 'email templates', $count); - } - - public function getTopicTitle() - { - return $this->_('Email templates'); - } - - protected function processForm($saveLabel = null, $data = null) - { - $model = $this->getModel(); - $isNew = ! $model->applyRequest($this->getRequest())->hasFilter(); - $form = new Gems_Email_MailTemplateForm($this->escort); - - $wasSaved = $form->processRequest($this->_request); - - if ($form->hasMessages()) { - $this->addMessage($form->getMessages()); - } - - if ($wasSaved) { - $this->addMessage(sprintf($this->_('%2$u %1$s saved'), $this->getTopic($wasSaved), $wasSaved)); - $this->afterSaveRoute($form->getValues()); - - } else { - $table = new MUtil_Html_TableElement(array('class' => 'formTable')); - $table->setAsFormLayout($form, true, true); - $table['tbody'][0][0]->class = 'label'; // Is only one row with formLayout, so all in output fields get class. - if ($links = $this->createMenuLinks(10)) { - $table->tf(); // Add empty cell, no label - $linksCell = $table->tf($links); - } - - return $form; - } - } -} Copied: branches/newUser/classes/Gems/Default/MailJobAction.php (from rev 139, trunk/library/classes/Gems/Default/MailJobAction.php) =================================================================== --- branches/newUser/classes/Gems/Default/MailJobAction.php (rev 0) +++ branches/newUser/classes/Gems/Default/MailJobAction.php 2011-10-25 15:58:01 UTC (rev 140) @@ -0,0 +1,212 @@ +<?php + +/** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * @package Gems + * @subpackage Default + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $ + */ + +/** + * + * + * @package Gems + * @subpackage Default + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.4.4 + */ +class Gems_Default_MailJobAction extends Gems_Controller_ModelSnippetActionAbstract +{ + /** + * + * @var ArrayObject + */ + public $project; + + + /** + * The automatically filtered result + * + * @param $resetMvc When true only the filtered resulsts + */ + public function autofilterAction($resetMvc = true) + { + $this->autofilterParameters['onEmpty'] = $this->_('No automatic mail jobs found...'); + + parent::autofilterAction($resetMvc); + } + + /** + * Action for showing a create new item page + */ + public function createAction() + { + $this->createEditParameters['formTitle'] = $this->_('New automatic mail job...'); + + parent::createAction(); + } + + /** + * Creates a model for getModel(). Called only for each new $action. + * + * The parameters allow you to easily adapt the model to the current action. The $detailed + * parameter was added, because the most common use of action is a split between detailed + * and summarized actions. + * + * @param boolean $detailed True when the current action is not in $summarizedActions. + * @param string $action The current action. + * @return MUtil_Model_ModelAbstract + */ + protected function createModel($detailed, $action) + { + $dbLookup = $this->util->getDbLookup(); + $dbTracks = $this->util->getTrackData(); + $translated = $this->util->getTranslated(); + $empty = $translated->getEmptyDropdownArray(); + $unselected = array('' => ''); + + $model = new MUtil_Model_TableModel('gems__mail_jobs'); + + Gems_Model::setChangeFieldsByPrefix($model, 'gmj'); + + $model->set('gmj_id_message', 'label', $this->_('Template'), 'multiOptions', $unselected + $dbLookup->getMailTemplates()); + $model->set('gmj_id_user_as', 'label', $this->_('By staff member'), + 'multiOptions', $unselected + $dbLookup->getActiveStaff(), 'default', $this->escort->getCurrentUserId(), + 'description', $this->_('Used for logging and possibly from address.')); + $model->set('gmj_active', 'label', $this->_('Active'), + 'multiOptions', $translated->getYesNo(), 'elementClass', 'Checkbox', 'required', true, + 'description', $this->_('Job is only run when active.')); + + $fromMethods = $unselected + $this->getBulkMailFromOptions(); + $model->set('gmj_from_method', 'label', $this->_('From address used'), 'multiOptions', $fromMethods); + if ($detailed) { + $model->set('gmj_from_fixed', 'label', $this->_('From other'), + 'description', sprintf($this->_("Only when '%s' is '%s'."), $model->get('gmj_from_method', 'label'), end($fromMethods))); + } + $model->set('gmj_process_method', 'label', $this->_('Processing Method'), 'multiOptions', $unselected + $translated->getBulkMailProcessOptions()); + $model->set('gmj_filter_mode', 'label', $this->_('Filter for'), 'multiOptions', $unselected + $this->getBulkMailFilterOptions()); + $model->set('gmj_filter_days_between', 'label', $this->_('Days between reminders'), 'validators[]', 'Digits'); + + if ($detailed) { + $model->set('gmj_id_organization', 'label', $this->_('Organization'), 'multiOptions', $empty + $dbLookup->getOrganizations()); + $model->set('gmj_id_track', 'label', $this->_('Track'), 'multiOptions', $empty + $dbTracks->getAllTracks()); + $model->set('gmj_id_survey', 'label', $this->_('Survey'), 'multiOptions', $empty + $dbTracks->getAllSurveys()); + } + + return $model; + } + + /** + * Action for showing a delete item page + */ + public function deleteAction() + { + $this->deleteParameters['deleteQuestion'] = $this->_('Do you want to delete this mail job?'); + $this->deleteParameters['displayTitle'] = $this->deleteParameters['deleteQuestion']; + + parent::deleteAction(); + } + + /** + * Action for showing a edit item page + */ + public function editAction() + { + $this->createEditParameters['formTitle'] = $this->_('Edit automatic mail job'); + + parent::editAction(); + } + + /** + * The types of mail filters + * + * @return array + */ + protected function getBulkMailFilterOptions() + { + return array( + 'N' => $this->_('First mail'), + 'R' => $this->_('Reminder'), + ); + } + + /** + * Options for from address use. + * + * @return array + */ + protected function getBulkMailFromOptions() + { + $results['O'] = $this->_('Use organizational from address'); + + if (isset($project->email['site']) && $project->email['site']) { + $results['S'] = sprintf($this->_('Use site %s address'), $project->email['site']); + } + + $results['U'] = $this->_("Use the 'By staff member' address"); + $results['F'] = $this->_('Other'); + + return $results; + } + + /** + * Action for showing a browse page + */ + public function indexAction() + { + $this->html->h3($this->_('Automatic mail jobs')); + + $lock = $this->util->getCronJobLock(); + if ($lock->isLocked()) { + $this->addMessage(sprintf($this->_('Automatic mails have been turned off since %s.'), $lock->getLockTime())); + + $request = $this->getRequest(); + if ($menuItem = $this->menu->findFirst(array($request->getControllerKey() => 'cron', $request->getActionKey() => 'cron-lock'))) { + $menuItem->set('label', $this->_('Turn Automatic Mail Jobs ON')); + } + } + + parent::indexAction(); + + $this->html->pInfo($this->_('With automatic mail jobs and a cron job on the server, mails can be sent without manual user action.')); + } + + /** + * Action for showing an item page + */ + public function showAction() + { + $this->showParameters['displayTitle'] = $this->_('Automatic mail job details'); + + parent::showAction(); + } +} Modified: branches/newUser/classes/Gems/Default/MailLogAction.php =================================================================== --- branches/newUser/classes/Gems/Default/MailLogAction.php 2011-10-25 15:34:11 UTC (rev 139) +++ branches/newUser/classes/Gems/Default/MailLogAction.php 2011-10-25 15:58:01 UTC (rev 140) @@ -137,7 +137,7 @@ */ public function showAction() { - $this->html->h3($this->_('Show Mail Activity Log item')); + $this->showParameters['displayTitle'] = $this->_('Show Mail Activity Log item'); // MUtil_Echo::track($this->indexParameters); parent::showAction(); Copied: branches/newUser/classes/Gems/Default/MailTemplateAction.php (from rev 139, trunk/library/classes/Gems/Default/MailTemplateAction.php) =================================================================== --- branches/newUser/classes/Gems/Default/MailTemplateAction.php (rev 0) +++ branches/newUser/classes/Gems/Default/MailTemplateAction.php 2011-10-25 15:58:01 UTC (rev 140) @@ -0,0 +1,130 @@ +<?php + +/** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * @package Gems + * @subpackage Default + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ + */ + +/** + * + * @package Gems + * @subpackage Default + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.1 + */ +class Gems_Default_MailTemplateAction extends Gems_Controller_BrowseEditAction +{ + /** + * Creates a model for getModel(). Called only for each new $action. + * + * The parameters allow you to easily adapt the model to the current action. The $detailed + * parameter was added, because the most common use of action is a split between detailed + * and summarized actions. + * + * @param boolean $detailed True when the current action is not in $summarizedActions. + * @param string $action The current action. + * $return MUtil_Model_ModelAbstract + */ + public function createModel($detailed, $action) + { + $model = new MUtil_Model_TableModel('gems__mail_templates'); + $model->set('gmt_subject', 'label', $this->_('Subject')); + + if ($detailed) { + $model->set('gmt_body', + 'label', $this->_('Message'), + 'itemDisplay', array('Gems_Email_EmailFormAbstract', 'displayMailText')); + } + + return $model; + } + + public function getAutoSearchElements(MUtil_Model_ModelAbstract $model, array $data) + { + $elements = parent::getAutoSearchElements($model, $data); + $options = array('' => $this->_('(all organizations)')) + $this->util->getDbLookup()->getOrganizations(); + + $elements[] = new Zend_Form_Element_Select('org_id', array('multiOptions' => $options)); + + return $elements; + } + + protected function getDataFilter(array $data) + { + if (isset($data['org_id']) && $data['org_id']) { + $organizationId = intval($data['org_id']); + return array("LOCATE('|$organizationId|', gmt_organizations) > 0"); + } + + return parent::getDataFilter($data); + } + + public function getTopic($count = 1) + { + return $this->plural('email template', 'email templates', $count); + } + + public function getTopicTitle() + { + return $this->_('Email templates'); + } + + protected function processForm($saveLabel = null, $data = null) + { + $model = $this->getModel(); + $isNew = ! $model->applyRequest($this->getRequest())->hasFilter(); + $form = new Gems_Email_MailTemplateForm($this->escort); + + $wasSaved = $form->processRequest($this->_request); + + if ($form->hasMessages()) { + $this->addMessage($form->getMessages()); + } + + if ($wasSaved) { + $this->addMessage(sprintf($this->_('%2$u %1$s saved'), $this->getTopic($wasSaved), $wasSaved)); + $this->afterSaveRoute($form->getValues()); + + } else { + $table = new MUtil_Html_TableElement(array('class' => 'formTable')); + $table->setAsFormLayout($form, true, true); + $table['tbody'][0][0]->class = 'label'; // Is only one row with formLayout, so all in output fields get class. + if ($links = $this->createMenuLinks(10)) { + $table->tf(); // Add empty cell, no label + $linksCell = $table->tf($links); + } + + return $form; + } + } +} Modified: branches/newUser/classes/Gems/Default/ProjectInformationAction.php =================================================================== --- branches/newUser/classes/Gems/Default/ProjectInformationAction.php 2011-10-25 15:34:11 UTC (rev 139) +++ branches/newUser/classes/Gems/Default/ProjectInformationAction.php 2011-10-25 15:58:01 UTC (rev 140) @@ -144,7 +144,8 @@ $data[$this->_('Server OS')] = php_uname('s'); $data[$this->_('Time on server')] = date('r'); - if (file_exists($this->escort->getMaintenanceLockFilename())) { + $lock = $this->util->getMaintenanceLock(); + if ($lock->isLocked()) { $label = $this->_('Turn Maintenance Mode OFF'); } else { $label = $this->_('Turn Maintenance Mode ON'); @@ -161,14 +162,13 @@ $this->html->buttonDiv($buttonList); } + /** + * Action that switches the maintenance lock on or off. + */ public function maintenanceAction() { - $lockFile = $this->escort->getMaintenanceLockFilename(); - if (file_exists($lockFile)) { - unlink($lockFile); - } else { - touch($lockFile); - } + // Switch lock + $this->util->getMaintenanceLock()->reverse(); // Dump the existing maintenance mode messages. $this->escort->getMessenger()->clearCurrentMessages(); Modified: branches/newUser/classes/Gems/Default/RoleAction.php =================================================================== --- branches/newUser/classes/Gems/Default/RoleAction.php 2011-10-25 15:34:11 UTC (rev 139) +++ branches/newUser/classes/Gems/Default/RoleAction.php 2011-10-25 15:58:01 UTC (rev 140) @@ -120,7 +120,7 @@ $disabled = $checkbox->getAttrib('disable'); if ($disabled) { - $values = array_merge($values, $disabled); + $values = array_merge((array) $values, $disabled); } $checkbox->setValue($values); return $form; @@ -139,10 +139,23 @@ $data['grl_parents'] = implode(',', $data['grl_parents']); } + //Always add nologin privilege to 'nologin' role + if (isset($data['grl_name']) && $data['grl_name'] == 'nologin') { + $data['grl_privileges'][] = 'pr.nologin'; + } elseif (isset($data['grl_name']) && $data['grl_name'] !== 'nologin') { + //Assign islogin to all other roles + $data['grl_privileges'][] = 'pr.islogin'; + } + if (isset($data['grl_privileges'])) { $data['grl_privileges'] = implode(',', $data['grl_privileges']); } + if(isset($data['grl_name']) && $data['grl_name'] == 'master') { + $form->getElement('grl_name')->setErrors(array($this->_('Illegal name'))); + return false; + } + return true; } @@ -171,6 +184,20 @@ return $model; } + public function editAction() + { + $model = $this->getModel(); + $data = $model->loadFirst(); + + //If we try to edit master, add an error message and reroute + if (isset($data['grl_name']) && $data['grl_name']=='master') { + $this->addMessage($this->_('Editing `master` is not allowed')); + $this->_reroute(array('action'=>'index'), true); + } + + parent::editAction(); + } + public function formatLongLine($line) { if (strlen($line) > 50) { @@ -195,6 +222,10 @@ $privileges = $this->menu->getUsedPrivileges(); asort($privileges); + //don't allow to edit the pr.nologin and pr.islogin privilege + unset($privileges['pr.nologin']); + unset($privileges['pr.islogin']); + return $privileges; } Modified: branches/newUser/classes/Gems/Default/StaffAction.php =================================================================== --- branches/newUser/classes/Gems/Default/StaffAction.php 2011-10-25 15:34:11 UTC (rev 139) +++ branches/newUser/classes/Gems/Default/StaffAction.php 2011-10-25 15:58:01 UTC (rev 140) @@ -92,7 +92,7 @@ { $dbLookup = $this->util->getDbLookup(); - $model->set('gsf_id_primary_group', 'multiOptions', MUtil_Lazy::call($dbLookup->getActiveStaffGroups)); + $model->set('gsf_id_primary_group', 'multiOptions', MUtil_Lazy::call($dbLookup->getAllowedStaffGroups)); if ($new) { $model->set('gsf_id_primary_group', 'default', $dbLookup->getDefaultGroup()); } else { @@ -125,11 +125,10 @@ if ($this->escort->hasPrivilege('pr.staff.edit.all')) { $bridge->addSelect('gsf_id_organization'); - $bridge->addSelect('gsf_id_primary_group'); } else { $bridge->addExhibitor('gsf_id_organization'); - $bridge->addSelect( 'gsf_id_primary_group', 'multiOptions', $dbLookup->getAllowedStaffGroups()); } + $bridge->addSelect('gsf_id_primary_group'); $bridge->addCheckbox('gsf_logout_on_survey', 'description', $this->_('If checked the user will logoff when answering a survey.')); $bridge->addSelect('gsf_iso_lang'); Modified: branches/newUser/classes/Gems/Email/EmailFormAbstract.php =================================================================== --- branches/newUser/classes/Gems/Email/EmailFormAbstract.php 2011-10-25 15:34:11 UTC (rev 139) +++ branches/newUser/classes/Gems/Email/EmailFormAbstract.php 2011-10-25 15:58:01 UTC (rev 140) @@ -345,7 +345,7 @@ $options = $this->model->get($name, 'maxlength', 'required'); $options['label'] = $this->escort->_('Subject'); - $options['size'] = $options['maxlength']; + $options['size'] = min(array($options['maxlength'], 80)); return new Zend_Form_Element_Text($name, $options); } Modified: branches/newUser/classes/Gems/Email/MultiMailForm.php =================================================================== --- branches/newUser/classes/Gems/Email/MultiMailForm.php 2011-10-25 15:34:11 UTC (rev 139) +++ branches/newUser/classes/Gems/Email/MultiMailForm.php 2011-10-25 15:58:01 UTC (rev 140) @@ -1,31 +1,31 @@ <?php - -/** - * Copyright (c) 2011, Erasmus MC - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Erasmus MC nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * * @version $Id$ * @package Gems * @subpackage Email @@ -69,15 +69,11 @@ protected function createMethodElement() { - $options = array( - 'M' => $this->escort->_('Send multiple mails per respondent, one for each checked token.'), - 'O' => $this->escort->_('Send one mail per respondent, mark all checked tokens as send.'), - 'A' => $this->escort->_('Send one mail per respondent, mark only mailed tokens as send.'), - ); + $options = $this->escort->getUtil()->getTranslated()->getBulkMailProcessOptions(); return new Zend_Form_Element_Radio('multi_method', array( 'label' => $this->escort->_('Method'), - 'multiOptions' => $options, + 'multiOptions' => $options, 'required' => true, )); } @@ -138,11 +134,11 @@ $title = null; } - return $this->_createMultiOption($tokenData, - $this->mailer->getTokenName($tokenData), - $tokenData['grs_email'], - $tokenData['survey_short'], - $title, + return $this->_createMultiOption($tokenData, + $this->mailer->getTokenName($tokenData), + $tokenData['grs_email'], + $tokenData['survey_short'], + $title, $menuFind); } @@ -202,7 +198,7 @@ $this->tokensData = $tokensData; $this->setTokenData(reset($tokensData)); - + return $this; } } Modified: branches/newUser/classes/Gems/Email/TemplateMailer.php =================================================================== --- branches/newUser/classes/Gems/Email/TemplateMailer.php 2011-10-25 15:34:11 UTC (rev 139) +++ branches/newUser/classes/Gems/Email/TemplateMailer.php 2011-10-25 15:58:01 UTC (rev 140) @@ -49,6 +49,12 @@ const MAIL_TLS = 2; /** + * + * @var Zend_Mail_Transport + */ + protected $defaultTransport = null; + + /** * @var GemsEscort $escort */ protected $escort; @@ -161,7 +167,7 @@ $mailServers[$from] = new Zend_Mail_Transport_Smtp($serverData['gms_server'], $options); } else { - $mailServers[$from] = null; + $mailServers[$from] = $this->defaultTransport; } } @@ -317,7 +323,7 @@ * @param string $from * @param string $from_name * @param array $tokenData - * @return boolean|string + * @return boolean|string String = error message from protocol. */ public function sendMail($to, $to_name, $from, $from_name, array $tokenData) { @@ -368,23 +374,39 @@ /** * Sets the body of the mail * @param string $body + * @return Gems_Email_TemplateMailer (continuation pattern) */ public function setBody($body) { $this->_body = $body; + return $this; } /** + * Set a different default transport protocol. + * + * @param Zend_Mail_Transport_Abstract $transport + * @return Gems_Email_TemplateMailer (continuation pattern) + */ + public function setDefaultTransport(Zend_Mail_Transport_Abstract $transport) + { + $this->defaultTransport = $transport; + return $this; + } + + /** * Sets sender (regular e-mail address) or one of: * 'O' - Uses the contact information of the selected organization * 'S' - Uses the site-wide contact information * 'U' - Uses the contact information of the currently logged in user * * @param string $from + * @return Gems_Email_TemplateMailer (continuation pattern) */ public function setFrom($from) { $this->_from = $from; + return $this; } /** @@ -394,15 +416,18 @@ * 'A' - Send one mail per respondent, mark only mailed tokens as send. * * @param string $method + * @return Gems_Email_TemplateMailer (continuation pattern) */ public function setMethod($method) { $this->_method = $method; + return $this; } /** * Sets the subject of the mail * @param string $subject + * @return Gems_Email_TemplateMailer (continuation pattern) */ public function setSubject($subject) { @@ -412,7 +437,6 @@ public function setTemplateId($templatedId) { $this->_templateId = $templatedId; - return $this; } @@ -438,22 +462,27 @@ } /** - * Sets a list of tokens + * Sets the li... [truncated message content] |
From: <gem...@li...> - 2011-10-27 09:04:05
|
Revision: 146 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=146&view=rev Author: matijsdejong Date: 2011-10-27 09:03:59 +0000 (Thu, 27 Oct 2011) Log Message: ----------- Merged changes 142-144 Modified Paths: -------------- branches/newUser/classes/Gems/Default/ConsentAction.php branches/newUser/classes/Gems/Default/ProjectInformationAction.php branches/newUser/classes/Gems/Default/ReceptionAction.php branches/newUser/classes/Gems/Default/RoleAction.php branches/newUser/classes/Gems/Menu/MenuAbstract.php branches/newUser/classes/Gems/Roles.php branches/newUser/classes/GemsEscort.php Property Changed: ---------------- branches/newUser/ Property changes on: branches/newUser ___________________________________________________________________ Modified: svn:mergeinfo - /trunk/library:114-122,125-139 + /trunk/library:114-122,125-139,142-144 Modified: branches/newUser/classes/Gems/Default/ConsentAction.php =================================================================== --- branches/newUser/classes/Gems/Default/ConsentAction.php 2011-10-26 17:18:45 UTC (rev 145) +++ branches/newUser/classes/Gems/Default/ConsentAction.php 2011-10-27 09:03:59 UTC (rev 146) @@ -1,35 +1,35 @@ <?php - -/** - * Copyright (c) 2011, Erasmus MC - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Erasmus MC nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - + /** - * + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * * @author Matijs de Jong * @since 1.0 * @version 1.1 @@ -38,22 +38,24 @@ */ /** - * + * * @author Matijs de Jong * @package Gems * @subpackage Default */ class Gems_Default_ConsentAction extends Gems_Controller_BrowseEditAction { + public $menuIndexIncludeLevel = 1; + public $sortKey = array('gco_order' => SORT_ASC); - /** - * Creates a model for getModel(). Called only for each new $action. - * - * The parameters allow you to easily adapt the model to the current action. The $detailed - * parameter was added, because the most common use of action is a split between detailed + /** + * Creates a model for getModel(). Called only for each new $action. + * + * The parameters allow you to easily adapt the model to the current action. The $detailed + * parameter was added, because the most common use of action is a split between detailed * and summarized actions. - * + * * @param boolean $detailed True when the current action is not in $summarizedActions. * @param string $action The current action. * @return MUtil_Model_ModelAbstract Modified: branches/newUser/classes/Gems/Default/ProjectInformationAction.php =================================================================== --- branches/newUser/classes/Gems/Default/ProjectInformationAction.php 2011-10-26 17:18:45 UTC (rev 145) +++ branches/newUser/classes/Gems/Default/ProjectInformationAction.php 2011-10-27 09:03:59 UTC (rev 146) @@ -153,7 +153,8 @@ $request = $this->getRequest(); $buttonList = $this->menu->getMenuList(); $buttonList->addParameterSources($request) - ->addByController($request->getControllerName(), 'maintenance', $label); + ->addByController($request->getControllerName(), 'maintenance', $label) + ->addByController($request->getControllerName(), 'cacheclean'); // $this->html->buttonDiv($buttonList); @@ -180,6 +181,15 @@ $this->_reroute(array($request->getActionKey() => 'index')); } + public function cachecleanAction() + { + $this->escort->cache->clean(); + $this->addMessage($this->_('Cache cleaned')); + // Redirect + $request = $this->getRequest(); + $this->_reroute(array($request->getActionKey() => 'index')); + } + public function phpAction() { $this->html->h2($this->_('Server PHP Info')); Modified: branches/newUser/classes/Gems/Default/ReceptionAction.php =================================================================== --- branches/newUser/classes/Gems/Default/ReceptionAction.php 2011-10-26 17:18:45 UTC (rev 145) +++ branches/newUser/classes/Gems/Default/ReceptionAction.php 2011-10-27 09:03:59 UTC (rev 146) @@ -46,6 +46,8 @@ */ class Gems_Default_ReceptionAction extends Gems_Controller_BrowseEditAction { + public $menuIndexIncludeLevel = 1; + public $sortKey = array('grc_id_reception_code' => SORT_ASC); public function addFormElements(MUtil_Model_FormBridge $bridge, MUtil_Model_ModelAbstract $model, array $data, $new = false) Modified: branches/newUser/classes/Gems/Default/RoleAction.php =================================================================== --- branches/newUser/classes/Gems/Default/RoleAction.php 2011-10-26 17:18:45 UTC (rev 145) +++ branches/newUser/classes/Gems/Default/RoleAction.php 2011-10-27 09:03:59 UTC (rev 146) @@ -46,6 +46,11 @@ */ class Gems_Default_RoleAction extends Gems_Controller_BrowseEditAction { + /** + * @var GemsEscort + */ + public $escort; + protected function _showTable($caption, $data, $nested = false) { $table = MUtil_Html_TableElement::createArray($data, $caption, $nested); @@ -107,6 +112,21 @@ } /** + * As the ACL might have to be updated, rebuild the acl + * + * @param array $data + * @param type $isNew + * @return type + */ + public function afterSave(array $data, $isNew) + { + $roles = $this->loader->getRoles($this->escort); + $roles->build(); + + return true; + } + + /** * Check the disabled (=inherited) privileges * * @param Gems_Form $form Modified: branches/newUser/classes/Gems/Menu/MenuAbstract.php =================================================================== --- branches/newUser/classes/Gems/Menu/MenuAbstract.php 2011-10-26 17:18:45 UTC (rev 145) +++ branches/newUser/classes/Gems/Menu/MenuAbstract.php 2011-10-27 09:03:59 UTC (rev 146) @@ -316,6 +316,7 @@ $page->addAction($this->_('Project'), null, 'project'); $page->addAction($this->_('Session'), null, 'session'); $page->addButtonOnly($this->_('Maintenance mode'), 'pr.maintenance', 'project-information', 'maintenance'); + $page->addButtonOnly($this->_('Clean cache'), 'pr.maintenance', 'project-information', 'cacheclean'); return $page; } Modified: branches/newUser/classes/Gems/Roles.php =================================================================== --- branches/newUser/classes/Gems/Roles.php 2011-10-26 17:18:45 UTC (rev 145) +++ branches/newUser/classes/Gems/Roles.php 2011-10-27 09:03:59 UTC (rev 146) @@ -241,13 +241,16 @@ private function save() { if ($this->_cache instanceof Zend_Cache_Core) { if (!$this->_cache->save($this->_acl, $this->_cacheid, array(), null)) - echo "MISLUKT!"; + throw new Gems_Exception('Failed to save acl to cache'); } } public function setCache($cache) { - if ($cache instanceof Zend_Cache_Core) + if ($cache instanceof Zend_Cache_Core) { $this->_cache = $cache; - } + } elseif ($cache instanceof GemsEscort) { + $this->_cache = $cache->cache; + } + } } \ No newline at end of file Modified: branches/newUser/classes/GemsEscort.php =================================================================== --- branches/newUser/classes/GemsEscort.php 2011-10-26 17:18:45 UTC (rev 145) +++ branches/newUser/classes/GemsEscort.php 2011-10-27 09:03:59 UTC (rev 146) @@ -138,6 +138,36 @@ } /** + * Create a default file cache for the Translate and DB adapters to speed up execution + * + * @return Zend_Cache_Core + */ + protected function _initCache() + { + $exists = false; + $cacheDir = GEMS_ROOT_DIR . "/var/cache/"; + if (!file_exists($cacheDir)) { + if (mkdir($cacheDir, 0777, true)) { + $exists = true; + } + } else { + $exists = true; + } + + if ($exists) { + $cacheFrontendOptions = array('automatic_serialization' => true); + $cacheBackendOptions = array('cache_dir' => $cacheDir); + + $cache = Zend_Cache::factory('Core', 'File', $cacheFrontendOptions, $cacheBackendOptions); + + Zend_Db_Table_Abstract::setDefaultMetadataCache($cache); + Zend_Translate::setCache($cache); + } + + return $cache; + } + + /** * Initialize the logger * * @return Gems_Log This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-27 15:38:05
|
Revision: 148 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=148&view=rev Author: matijsdejong Date: 2011-10-27 15:37:58 +0000 (Thu, 27 Oct 2011) Log Message: ----------- For #31: gems__staff split into gems__users Temp fix for moving to new password situation while retaining the older versions. DeleteValues moved up to DatabaseModelAbstract. setModelParameters() added to menu for 2 parameter menu items. Modified Paths: -------------- branches/newUser/classes/Gems/Auth.php branches/newUser/classes/Gems/Default/CronAction.php branches/newUser/classes/Gems/Default/IndexAction.php branches/newUser/classes/Gems/Default/OptionAction.php branches/newUser/classes/Gems/Default/RespondentAction.php branches/newUser/classes/Gems/Default/StaffAction.php branches/newUser/classes/Gems/Default/TokenPlanAction.php branches/newUser/classes/Gems/Menu/MenuAbstract.php branches/newUser/classes/Gems/Menu/SubMenuItem.php branches/newUser/classes/Gems/Model/UserModel.php branches/newUser/classes/Gems/User/RespondentUser.php branches/newUser/classes/Gems/User/StaffUser.php branches/newUser/classes/Gems/Util/DbLookup.php branches/newUser/classes/Gems/Validate/GemsPasswordUsername.php branches/newUser/classes/GemsEscort.php branches/newUser/classes/MUtil/Model/DatabaseModelAbstract.php branches/newUser/classes/MUtil/Model/JoinModel.php branches/newUser/classes/MUtil/Model/ModelAbstract.php branches/newUser/classes/MUtil/Model/TableBridgeAbstract.php branches/newUser/classes/MUtil/Model/TableModel.php branches/newUser/configs/db/patches.sql branches/newUser/configs/db/tables/gems__staff.20.sql branches/newUser/configs/db/tables/gems__users.10.sql branches/newUser/controllers/StaffController.php Modified: branches/newUser/classes/Gems/Auth.php =================================================================== --- branches/newUser/classes/Gems/Auth.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/Gems/Auth.php 2011-10-27 15:37:58 UTC (rev 148) @@ -98,8 +98,8 @@ * Lookup last failed login and number of failed logins */ try { - $sql = "SELECT gsf_failed_logins, UNIX_TIMESTAMP(gsf_last_failed) - AS gsf_last_failed FROM gems__staff WHERE gsf_login = ?"; + $sql = "SELECT gsu_failed_logins, UNIX_TIMESTAMP(gsu_last_failed) + AS gsu_last_failed FROM gems__users WHERE gsu_login = ?"; $results = $this->db->fetchRow($sql, array($username)); } catch (Zend_Db_Exception $zde) { //If we need to apply a db patch, just use a default value @@ -107,10 +107,10 @@ MUtil_Echo::r(GemsEscort::getInstance()->translate->_('Please update the database')); } - $delay = pow($results['gsf_failed_logins'], $this->_delayFactor); - $remaining = ($results['gsf_last_failed'] + $delay) - time(); + $delay = pow($results['gsu_failed_logins'], $this->_delayFactor); + $remaining = ($results['gsu_last_failed'] + $delay) - time(); - if ($results['gsf_failed_logins'] > 0 && $remaining > 0) { + if ($results['gsu_failed_logins'] > 0 && $remaining > 0) { //$this->_obscureValue = false; $result = $this->_error(self::ERROR_PASSWORD_DELAY, ceil($remaining / 60)); } Modified: branches/newUser/classes/Gems/Default/CronAction.php =================================================================== --- branches/newUser/classes/Gems/Default/CronAction.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/Gems/Default/CronAction.php 2011-10-27 15:37:58 UTC (rev 148) @@ -125,7 +125,7 @@ */ protected function getUserLogin($userId) { - return $this->db->fetchOne("SELECT gsf_login FROM gems__staff WHERE gsf_id_user = ?", $userId); + return $this->db->fetchOne("SELECT gsu_login FROM gems__users WHERE gsu_id_user = ?", $userId); } public function indexAction() Modified: branches/newUser/classes/Gems/Default/IndexAction.php =================================================================== --- branches/newUser/classes/Gems/Default/IndexAction.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/Gems/Default/IndexAction.php 2011-10-27 15:37:58 UTC (rev 148) @@ -74,7 +74,7 @@ * @return Zend_Auth_Adapter_Interface */ protected function _getAuthAdapter($formValues) { - $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__staff', 'gsf_login', 'gsf_password'); + $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__users', 'gsu_login', 'gsu_password'); $adapter->setIdentity($formValues['userlogin']); $adapter->setCredential($this->escort->passwordHash(null, $formValues['password'], false)); return $adapter; @@ -201,6 +201,19 @@ $adapter = $this->_getAuthAdapter($form->getValues()); $auth = Gems_Auth::getInstance(); $result = $auth->authenticate($adapter, $_POST['userlogin']); + + // Allow login using old password. + if ((! $result->isValid()) && ($userid = $this->db->fetchOne("SELECT gsu_id_user FROM gems__users WHERE gsu_active = 1 AND gsu_password IS NULL AND gsu_login = ?", $_POST['userlogin']))) { + + $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__staff', 'gsf_id_user', 'gsf_password'); + $adapter->setIdentity($userid); + $adapter->setCredential(md5($_POST['password'], false)); + $result = $auth->authenticate($adapter, $_POST['userlogin']); + MUtil_Echo::track('old autho'); + } else { + MUtil_Echo::track('new autho'); + } + if (!$result->isValid()) { // Invalid credentials $errors = $result->getMessages(); @@ -316,19 +329,19 @@ } if ($this->_request->isPost() && $form->isValid($_POST)) { - $sql = $this->db->quoteInto("SELECT gsf_id_user,gsf_email,gsf_reset_key,DATEDIFF(NOW(), gsf_reset_req) AS gsf_days FROM gems__staff WHERE gsf_login = ?", $_POST['userlogin']); + $sql = $this->db->quoteInto("SELECT gsu_id_user, gsf_email, gsu_reset_key, DATEDIFF(NOW(), gsu_reset_requested) AS gsf_days FROM gems__users INNER JOIN gems__staff ON gsu_id_user = gsf_id_user WHERE gsu_login = ?", $_POST['userlogin']); $result = $this->db->fetchRow($sql); if (empty($result) || empty($result['gsf_email'])) { $this->addMessage($this->_('No such user found or no e-mail address known')); - } else if (!empty($result['gsf_reset_key']) && $result['gsf_days'] < 1) { + } else if (!empty($result['gsu_reset_key']) && $result['gsf_days'] < 1) { $this->addMessage($this->_('Reset e-mail already sent, please try again after 24 hours')); } else { $email = $result['gsf_email']; $key = md5(time() . $email); $url = $this->util->getCurrentURI('index/resetpassword/key/' . $key); - $this->db->update('gems__staff', array('gsf_reset_key' => $key, 'gsf_reset_req' => new Zend_Db_Expr('NOW()')), 'gsf_id_user = ' . $result['gsf_id_user']); + $this->db->update('gems__users', array('gsu_reset_key' => $key, 'gsu_reset_requested' => new Zend_Db_Expr('NOW()')), 'gsu_id_user = ' . $result['gsu_id_user']); $mail->setSubject('Password reset requested'); $mail->setBodyText('To reset your password, please click this link: ' . $url); @@ -344,7 +357,7 @@ } } } else if ($key = $this->_request->getParam('key')) { - $sql = $this->db->quoteInto("SELECT gsf_id_user,gsf_email FROM gems__staff WHERE gsf_reset_key = ?", $key); + $sql = $this->db->quoteInto("SELECT gsu_id_user, gsf_email FROM gems__users INNER JOIN gems__staff ON gsu_id_user = gsf_id_user WHERE gsu_reset_key = ?", $key); $result = $this->db->fetchRow($sql); if (!empty($result)) { @@ -360,7 +373,7 @@ try { $mail->send(); $this->addMessage($this->_('An e-mail was sent containing your new password')); - $this->db->update('gems__staff', array('gsf_reset_key' => new Zend_Db_Expr('NULL'), 'gsf_reset_req' => new Zend_Db_Expr('NULL'), 'gsf_password' => $passwordHash), 'gsf_id_user = ' . $result['gsf_id_user']); + $this->db->update('gems__users', array('gsu_reset_key' => new Zend_Db_Expr('NULL'), 'gsu_reset_requested' => new Zend_Db_Expr('NULL'), 'gsu_password' => $passwordHash), 'gsu_id_user = ' . $result['gsu_id_user']); $this->_reroute(array('action' => 'index'), true); } catch (Exception $e) { $this->addMessage($this->_('Unable to send e-mail')); Modified: branches/newUser/classes/Gems/Default/OptionAction.php =================================================================== --- branches/newUser/classes/Gems/Default/OptionAction.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/Gems/Default/OptionAction.php 2011-10-27 15:37:58 UTC (rev 148) @@ -61,8 +61,10 @@ */ protected function addFormElements(MUtil_Model_FormBridge $bridge, MUtil_Model_ModelAbstract $model, array $data, $new = false) { + $bridge->addHidden( 'gsu_id_user'); + $bridge->addHidden( 'gsu_id_organization'); $bridge->addHidden( 'gsf_id_user'); - $bridge->addExhibitor('gsf_login', array('size' => 15, 'minlength' => 4)); + $bridge->addExhibitor('gsu_login', array('size' => 15, 'minlength' => 4)); $bridge->addText( 'gsf_first_name'); $bridge->addText( 'gsf_surname_prefix'); $bridge->addText( 'gsf_last_name'); @@ -71,12 +73,11 @@ $bridge->addRadio( 'gsf_gender', 'separator', ''); $bridge->addSelect( 'gsf_iso_lang', array('label' => $this->_('Language'), 'multiOptions' => $this->util->getLocalized()->getLanguages())); - $bridge->addCheckbox( 'gsf_logout_on_survey', 'label', $this->_('Logout on survey'), 'description', $this->_('If checked you will logoff after answering a survey.')); } public function afterSave(array $data, $isNew) { - $this->escort->loadLoginInfo($data['gsf_login']); + $this->escort->loadLoginInfo($data['gsu_login']); } public function changePasswordAction() @@ -86,15 +87,18 @@ *************/ $form = $this->createForm(); - // Veld current password - $element = new Zend_Form_Element_Password('old_password'); - $element->setLabel($this->_('Current password')); - $element->setAttrib('size', 10); - $element->setAttrib('maxlength', 20); - $element->setRenderPassword(true); - $element->setRequired(true); - $element->addValidator(new Gems_Validate_GemsPasswordUsername($this->session->user_login, 'old_password', $this->db)); - $form->addElement($element); + $sql = "SELECT CASE WHEN gsu_password IS NULL THEN 0 ELSE 1 END FROM gems__users WHERE gsu_id_user = ? AND gsu_id_organization = ?"; + if ($this->db->fetchOne($sql, array($this->session->user_id, $this->session->user_organization_id))) { + // Veld current password + $element = new Zend_Form_Element_Password('old_password'); + $element->setLabel($this->_('Current password')); + $element->setAttrib('size', 10); + $element->setAttrib('maxlength', 20); + $element->setRenderPassword(true); + $element->setRequired(true); + $element->addValidator(new Gems_Validate_GemsPasswordUsername($this->session->user_login, 'old_password', $this->db)); + $form->addElement($element); + } // Veld new password $element = new Zend_Form_Element_Password('new_password'); @@ -127,8 +131,9 @@ ****************/ if ($this->_request->isPost() && $form->isValid($_POST)) { - $data['gsf_id_user'] = $this->session->user_id; - $data['gsf_password'] = $this->escort->passwordHash(null,$_POST['new_password']); + $data['gsu_id_user'] = $this->session->user_id; + $data['gsu_id_organization'] = $this->session->user_organization_id; + $data['gsu_password'] = $this->escort->passwordHash(null, $_POST['new_password']); $this->getModel()->save($data); @@ -180,10 +185,10 @@ */ public function createModel($detailed, $action) { - $model = new MUtil_Model_TableModel('gems__staff'); - $model->canCreate = false; + $model = new Gems_Model_UserModel('staff', 'gems__staff', array('gsu_id_user' => 'gsf_id_user'), 'gsf'); + $model->copyKeys(); - $model->set('gsf_login', 'label', $this->_('Login Name')); + $model->set('gsu_login', 'label', $this->_('Login Name')); $model->set('gsf_email', 'label', $this->_('E-Mail')); $model->set('gsf_first_name', 'label', $this->_('First name')); $model->set('gsf_surname_prefix', 'label', $this->_('Surname prefix'), 'description', 'de, van der, \'t, etc...'); @@ -191,14 +196,12 @@ $model->set('gsf_gender', 'label', $this->_('Gender'), 'multiOptions', $this->util->getTranslated()->getGenders()); - Gems_Model::setChangeFieldsByPrefix($model, 'gsf'); - return $model; } public function editAction() { - $this->getModel()->setFilter(array('gsf_id_user' => $this->session->user_id)); + $this->getModel()->setFilter(array('gsu_id_user' => $this->session->user_id)); if ($form = $this->processForm()) { $this->html->h3(sprintf($this->_('Options'), $this->getTopic())); Modified: branches/newUser/classes/Gems/Default/RespondentAction.php =================================================================== --- branches/newUser/classes/Gems/Default/RespondentAction.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/Gems/Default/RespondentAction.php 2011-10-27 15:37:58 UTC (rev 148) @@ -326,8 +326,8 @@ $values = $this->db->fetchPairs(" SELECT gsf_id_user, CONCAT(gsf_last_name, ', ', COALESCE(CONCAT(gsf_first_name, ' '), ''), COALESCE(gsf_surname_prefix, '')) AS name - FROM gems__staff INNER JOIN gems__groups ON gsf_id_primary_group = ggp_id_group - WHERE gsf_active=1 AND gsf_id_organization = ? AND ggp_role = 'physician' + FROM (gems__users INNER JOIN gems__staff ON gsu_id_user = gsf_id_user) INNER JOIN gems__groups ON gsf_id_primary_group = ggp_id_group + WHERE gsu_active=1 AND gsu_id_organization = ? AND ggp_role = 'physician' ORDER BY 2", $organizationId); $session->physicians = $values; Modified: branches/newUser/classes/Gems/Default/StaffAction.php =================================================================== --- branches/newUser/classes/Gems/Default/StaffAction.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/Gems/Default/StaffAction.php 2011-10-27 15:37:58 UTC (rev 148) @@ -44,7 +44,7 @@ */ class Gems_Default_StaffAction extends Gems_Controller_BrowseEditAction { - public $filterStandard = array('gsf_active' => 1); + public $filterStandard = array('gsu_active' => 1); public $sortKey = array('name' => SORT_ASC); protected $_instanceId; @@ -96,18 +96,27 @@ if ($new) { $model->set('gsf_id_primary_group', 'default', $dbLookup->getDefaultGroup()); } else { - $model->set('gsf_password', 'description', $this->_('Enter only when changing')); - $model->setSaveWhenNotNull('gsf_password'); + $model->set('gsu_password', 'description', $this->_('Enter only when changing')); + $model->setSaveWhenNotNull('gsu_password'); } - $model->setOnSave('gsf_password', array($this->escort, 'passwordHash')); + $model->setOnSave('gsu_password', array($this->escort, 'passwordHash')); $ucfirst = new Zend_Filter_Callback('ucfirst'); - $bridge->addHidden( 'gsf_id_user'); - $bridge->addText( 'gsf_login', 'size', 15, 'minlength', 4, - 'validator', $model->createUniqueValidator('gsf_login')); + $bridge->addHidden( 'gsu_id_user'); + $bridge->addHidden( 'gsf_id_user'); // Needed for e-mail validation + $bridge->addText( 'gsu_login', 'size', 15, 'minlength', 4, + 'validator', $model->createUniqueValidator('gsu_login')); - $bridge->addPassword('gsf_password', + // Can the organization be changed? + if ($this->escort->hasPrivilege('pr.staff.edit.all')) { + $bridge->addHiddenMulti($model->getKeyCopyName('gsu_id_organization')); + $bridge->addSelect('gsu_id_organization'); + } else { + $bridge->addExhibitor('gsu_id_organization'); + } + + $bridge->addPassword('gsu_password', 'label', $this->_('Password'), 'minlength', $this->project->passwords['MinimumLength'], // 'renderPassword', true, @@ -123,11 +132,6 @@ $bridge->addFilter( 'gsf_last_name', $ucfirst); $bridge->addText( 'gsf_email', array('size' => 30))->addValidator('SimpleEmail')->addValidator($model->createUniqueValidator('gsf_email')); - if ($this->escort->hasPrivilege('pr.staff.edit.all')) { - $bridge->addSelect('gsf_id_organization'); - } else { - $bridge->addExhibitor('gsf_id_organization'); - } $bridge->addSelect('gsf_id_primary_group'); $bridge->addCheckbox('gsf_logout_on_survey', 'description', $this->_('If checked the user will logoff when answering a survey.')); @@ -136,15 +140,15 @@ public function afterFormLoad(array &$data, $isNew) { - if (array_key_exists('gsf_login', $data)) { - $this->_instanceId = $data['gsf_login']; + if (array_key_exists('gsu_login', $data)) { + $this->_instanceId = $data['gsu_login']; } $sql = "SELECT ggp_id_group,ggp_role FROM gems__groups WHERE ggp_id_group = " . (int) $data['gsf_id_primary_group']; $groups = $this->db->fetchPairs($sql); if (! ($this->escort->hasPrivilege('pr.staff.edit.all') || - $data['gsf_id_organization'] == $this->escort->getCurrentOrganization())) { + $data['gsu_id_organization'] == $this->escort->getCurrentOrganization())) { throw new Zend_Exception($this->_('You are not allowed to edit this staff member.')); } } @@ -164,18 +168,21 @@ { // MUtil_Model::$verbose = true; - $model = new MUtil_Model_TableModel('gems__staff'); + $model = new Gems_Model_UserModel('staff', 'gems__staff', array('gsu_id_user' => 'gsf_id_user'), 'gsf'); + if ($detailed) { + $model->copyKeys(); + } //$model->resetOrder(); - $model->set('gsf_login', 'label', $this->_('Login')); + $model->set('gsu_login', 'label', $this->_('Login')); $model->set('name', 'label', $this->_('Name'), 'column_expression', "CONCAT(COALESCE(CONCAT(gsf_last_name, ', '), '-, '), COALESCE(CONCAT(gsf_first_name, ' '), ''), COALESCE(gsf_surname_prefix, ''))"); $model->set('gsf_email', 'label', $this->_('E-Mail'), 'itemDisplay', 'MUtil_Html_AElement::ifmail'); if ($detailed || $this->escort->hasPrivilege('pr.staff.see.all')) { - $this->menu->getParameterSource()->offsetSet('gsf_id_organization', $this->escort->getCurrentOrganization()); + $this->menu->getParameterSource()->offsetSet('gsu_id_organization', $this->escort->getCurrentOrganization()); - $model->set('gsf_id_organization', 'label', $this->_('Organization'), + $model->set('gsu_id_organization', 'label', $this->_('Organization'), 'multiOptions', $this->util->getDbLookup()->getOrganizations(), 'default', $this->escort->getCurrentOrganization()); } @@ -188,10 +195,8 @@ $model->set('gsf_logout_on_survey', 'label', $this->_('Logout on survey'), 'multiOptions', $this->util->getTranslated()->getYesNo()); } - $model->setDeleteValues('gsf_active', 0); + $model->setDeleteValues('gsu_active', 0); - Gems_Model::setChangeFieldsByPrefix($model, 'gsf'); - return $model; } @@ -201,8 +206,8 @@ if ($this->escort->hasPrivilege('pr.staff.see.all')) { // Select organization - $options = array('' => $this->_('(all organizations)')) + $this->getModel()->get('gsf_id_organization', 'multiOptions'); - $select = new Zend_Form_Element_Select('gsf_id_organization', array('multiOptions' => $options)); + $options = array('' => $this->_('(all organizations)')) + $this->getModel()->get('gsu_id_organization', 'multiOptions'); + $select = new Zend_Form_Element_Select('gsu_id_organization', array('multiOptions' => $options)); // Position as second element $search = array_shift($elements); @@ -227,7 +232,7 @@ $filter = parent::getDataFilter($data); if (! $this->escort->hasPrivilege('pr.staff.see.all')) { - $filter['gsf_id_organization'] = $this->escort->getCurrentOrganization(); + $filter['gsu_id_organization'] = $this->escort->getCurrentOrganization(); } return $filter; } @@ -257,8 +262,8 @@ // Model filter has now been set. $data = $this->getModel()->loadFirst(); - $this->_setParam('gsf_id_organization', $data['gsf_id_organization']); - $this->menu->getParameterSource()->offsetSet('gsf_id_organization', $data['gsf_id_organization']); + $this->_setParam('gsu_id_organization', $data['gsu_id_organization']); + $this->menu->getParameterSource()->offsetSet('gsu_id_organization', $data['gsu_id_organization']); } return parent::getShowTable($columns, $filter, $sort); } Modified: branches/newUser/classes/Gems/Default/TokenPlanAction.php =================================================================== --- branches/newUser/classes/Gems/Default/TokenPlanAction.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/Gems/Default/TokenPlanAction.php 2011-10-27 15:37:58 UTC (rev 148) @@ -351,9 +351,9 @@ COALESCE(gems__staff.gsf_first_name, ''), COALESCE(CONCAT(' ', gems__staff.gsf_surname_prefix), '') ) AS gsf_name - FROM gems__staff INNER JOIN gems__respondent2track ON gsf_id_user = gr2t_created_by + FROM (gems__users INNER JOIN gems__staff ON gsu_id_user = gsf_id_user) INNER JOIN gems__respondent2track ON gsu_id_user = gr2t_created_by WHERE gr2t_id_organization = $orgId AND - gsf_active = 1 AND + gsu_active = 1 AND gr2t_active = 1"; $elements[] = $this->_createSelectElement('gr2t_created_by', $sql, $this->_('(all staff)')); Modified: branches/newUser/classes/Gems/Menu/MenuAbstract.php =================================================================== --- branches/newUser/classes/Gems/Menu/MenuAbstract.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/Gems/Menu/MenuAbstract.php 2011-10-27 15:37:58 UTC (rev 148) @@ -381,13 +381,12 @@ $page = $this->addPage($label, 'pr.staff', 'staff', 'index', $other); $page->addAutofilterAction(); $page->addCreateAction(); - $page->addShowAction(); - if ($this->escort->hasPrivilege('pr.staff.edit.all')) { - $page->addEditAction(); - $page->addDeleteAction(); - } else { - $page->addEditAction()->setParameterFilter('gsf_id_organization', $this->escort->getCurrentOrganization()); - $page->addDeleteAction()->setParameterFilter('gsf_id_organization', $this->escort->getCurrentOrganization()); + $page->addShowAction()->setModelParameters(2); + $editPage = $page->addEditAction()->setModelParameters(2); + $delPage = $page->addDeleteAction()->setModelParameters(2); + if (! $this->escort->hasPrivilege('pr.staff.edit.all')) { + $editPage->setParameterFilter('gsu_id_organization', $this->escort->getCurrentOrganization()); + $delPage->setParameterFilter('gsu_id_organization', $this->escort->getCurrentOrganization()); } return $page; Modified: branches/newUser/classes/Gems/Menu/SubMenuItem.php =================================================================== --- branches/newUser/classes/Gems/Menu/SubMenuItem.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/Gems/Menu/SubMenuItem.php 2011-10-27 15:37:58 UTC (rev 148) @@ -417,7 +417,7 @@ } $menu = $this->addAction($label, $privilege, 'delete', $other); - $menu->addParameters(MUtil_Model::REQUEST_ID); + $menu->setModelParameters(1); return $menu; } @@ -436,7 +436,7 @@ } $menu = $this->addAction($label, $privilege, 'edit', $other); - $menu->addParameters(MUtil_Model::REQUEST_ID); + $menu->setModelParameters(1); return $menu; } @@ -475,6 +475,17 @@ return $this; } + /** + * Add required parameters - shown in the url - for this + * menu item. + * + * Numeric array keys are changed into the same string as the + * array value. + * + * @param mixed $arrayOrKey1 MUtil_Ra::pairs named array + * @param mixed $key2 + * @return Gems_Menu_SubMenuItem (continuation pattern) + */ public function addNamedParameters($arrayOrKey1 = null, $altName1 = null) { $params = MUtil_Ra::pairs(func_get_args()); @@ -483,16 +494,8 @@ $this->_parameters = new MUtil_Lazy_ArrayWrap(); } foreach ($params as $param => $name) { - if (! $name) { - if (is_int($param)) { - throw new Zend_Exception('Invalid integer required parameter key with empty name.'); - } else { - $name = $param; - } - } else { - if (is_int($param)) { - $param = $name; - } + if (is_int($param)) { + $param = $name; } $this->_requiredParameters[$param] = $name; $this->_parameters[$param] = MUtil_Lazy::L($name); @@ -546,7 +549,7 @@ } $menu = $this->addAction($label, $privilege, 'show', $other); - $menu->addParameters(MUtil_Model::REQUEST_ID); + $menu->setModelParameters(1); return $menu; } @@ -755,6 +758,41 @@ return $this; } + /** + * Defines the number of named parameters using the model naming + * convention: id=x or id1=x id2=y + * + * @see setNamedParamenters() + * + * @param int $idCount The number of parameters to define + * @return Gems_Menu_SubMenuItem (continuation pattern) + */ + public function setModelParameters($idCount) + { + $params = array(); + if (1 == $idCount) { + $params[MUtil_Model::REQUEST_ID] = MUtil_Model::REQUEST_ID; + } else { + for ($i = 1; $i <= $idCount; $i++) { + $params[MUtil_Model::REQUEST_ID . $i] = MUtil_Model::REQUEST_ID . $i; + } + } + $this->setNamedParameters($params); + + return $this; + } + + /** + * Set the required parameters - shown in the url - for this + * menu item. + * + * Numeric array keys are changed into the same string as the + * array value. + * + * @param mixed $arrayOrKey1 MUtil_Ra::pairs named array + * @param mixed $key2 + * @return Gems_Menu_SubMenuItem (continuation pattern) + */ public function setNamedParameters($arrayOrKey1 = null, $key2 = null) { $params = MUtil_Ra::pairs(func_get_args()); Modified: branches/newUser/classes/Gems/Model/UserModel.php =================================================================== --- branches/newUser/classes/Gems/Model/UserModel.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/Gems/Model/UserModel.php 2011-10-27 15:37:58 UTC (rev 148) @@ -82,6 +82,8 @@ */ protected function _createUserId() { + $db = $this->getAdapter(); + $max = $this->userIdLen; do { @@ -92,7 +94,7 @@ // Make it a number $out = intval($out); - } while ($this->db->fetchOne('SELECT gsu_id_user FROM gems__users WHERE gsu_id_user = ?', $out)); + } while ($db->fetchOne('SELECT gsu_id_user FROM gems__users WHERE gsu_id_user = ?', $out)); return $out; } @@ -112,6 +114,6 @@ $newValues['gsu_id_user'] = $this->_createUserId(); } - parent::save($newValues, $filter, $saveTables); + return parent::save($newValues, $filter, $saveTables); } } Modified: branches/newUser/classes/Gems/User/RespondentUser.php =================================================================== --- branches/newUser/classes/Gems/User/RespondentUser.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/Gems/User/RespondentUser.php 2011-10-27 15:37:58 UTC (rev 148) @@ -38,6 +38,18 @@ /** * * +-- PATCH: New user login structure +INSERT INTO gems__users (gsu_id_user, gsu_login, gsu_id_organization, gsu_user_class, gsu_active, + gsu_password, gsu_failed_logins, gsu_last_failed, gsu_reset_key, gsu_reset_requested, gsu_reset_required, + gsu_changed, gsu_changed_by, gsu_created, gsu_created_by) + SELECT grs_id_user, gr2o_patient_nr, gr2o_id_organization, 'RespondentUser', CASE WHEN gr2o_reception_code = 'OK' THEN 1 ELSE 0 END, + NULL, 0, NULL, NULL, NULL, 0, + gr2o_changed, gr2o_changed_by, gr2o_created, gr2o_created_by + FROM gems__respondents INNER JOIN gems__respondent2org ON grs_id_user = gr2o_id_user + INNER JOIN gems__organizations ON gr2o_id_organization = gor_id_organization + WHERE gor_name = 'HCU / Xpert Clinic'; + + * * @package Gems * @subpackage User * @copyright Copyright (c) 2011 Erasmus MC Modified: branches/newUser/classes/Gems/User/StaffUser.php =================================================================== --- branches/newUser/classes/Gems/User/StaffUser.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/Gems/User/StaffUser.php 2011-10-27 15:37:58 UTC (rev 148) @@ -57,11 +57,11 @@ $select->from('gems__users') ->join('gems__staff', 'gsu_login = gsf_id_user') ->join('gems__groups', 'gsf_id_primary_group = ggp_id_group') - ->join('gems__organizations', 'gsf_id_organization = gor_id_organization') + ->join('gems__organizations', 'gsu_id_organization = gor_id_organization') ->where('ggp_group_active = 1') ->where('gor_active = 1') - ->where('gsf_active = 1') - ->where('gsf_login = ?', $this->getLoginName()) + ->where('gsu_active = 1') + ->where('gsu_login = ?', $this->getLoginName()) ->limit(1); return $select; Modified: branches/newUser/classes/Gems/Util/DbLookup.php =================================================================== --- branches/newUser/classes/Gems/Util/DbLookup.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/Gems/Util/DbLookup.php 2011-10-27 15:37:58 UTC (rev 148) @@ -105,7 +105,7 @@ if (! $data) { $data = $this->db->fetchPairs("SELECT gsf_id_user, CONCAT(COALESCE(gsf_last_name, '-'), ', ', COALESCE(gsf_first_name, ''), COALESCE(CONCAT(' ', gsf_surname_prefix), '')) - FROM gems__staff WHERE gsf_active = 1 ORDER BY gsf_last_name, gsf_first_name, gsf_surname_prefix"); + FROM gems__users INNER JOIN gems__staff ON gsu_id_user = gsf_id_user WHERE gsu_active = 1 ORDER BY gsf_last_name, gsf_first_name, gsf_surname_prefix"); } return $data; Modified: branches/newUser/classes/Gems/Validate/GemsPasswordUsername.php =================================================================== --- branches/newUser/classes/Gems/Validate/GemsPasswordUsername.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/Gems/Validate/GemsPasswordUsername.php 2011-10-27 15:37:58 UTC (rev 148) @@ -86,7 +86,7 @@ */ public function __construct($usernameField, $passwordField, Zend_Db_Adapter_Abstract $adapter = null, $delayFactor = null) { - parent::__construct('gems__staff', 'gsf_login', null, $adapter); + parent::__construct('gems__users', 'gsu_login', null, $adapter); $this->_usernameField = $usernameField; $this->_passwordField = $passwordField; @@ -137,7 +137,7 @@ } } - $condition = $this->_adapter->quoteIdentifier('gsf_password') . ' = ?'; + $condition = $this->_adapter->quoteIdentifier('gsu_password') . ' = ?'; $this->_exclude = $this->_adapter->quoteInto($condition, md5($password)); try { @@ -145,8 +145,8 @@ * Lookup last failed login and number of failed logins */ try { - $sql = "SELECT gsf_failed_logins, UNIX_TIMESTAMP(gsf_last_failed) - AS gsf_last_failed FROM {$this->_table} WHERE gsf_login = ?"; + $sql = "SELECT gsu_failed_logins, UNIX_TIMESTAMP(gsu_last_failed) + AS gsu_last_failed FROM {$this->_table} WHERE gsu_login = ?"; $results = $this->_adapter->fetchRow($sql, array($username)); } catch (Zend_Db_Exception $zde) { //If we need to apply a db patch, just use a default value @@ -154,10 +154,10 @@ MUtil_Echo::r(GemsEscort::getInstance()->translate->_('Please update the database')); } - $delay = pow($results['gsf_failed_logins'], $this->_delayFactor); - $remaining = ($results['gsf_last_failed'] + $delay) - time(); + $delay = pow($results['gsu_failed_logins'], $this->_delayFactor); + $remaining = ($results['gsu_last_failed'] + $delay) - time(); - if ($results['gsf_failed_logins'] > 0 && $remaining > 0) { + if ($results['gsu_failed_logins'] > 0 && $remaining > 0) { $this->_obscureValue = false; $this->_error(self::ERROR_PASSWORD_DELAY, ceil($remaining / 60)); return false; Modified: branches/newUser/classes/GemsEscort.php =================================================================== --- branches/newUser/classes/GemsEscort.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/GemsEscort.php 2011-10-27 15:37:58 UTC (rev 148) @@ -927,7 +927,7 @@ * Reset number of failed logins */ try { - $sql = "UPDATE gems__staff SET gsf_failed_logins = 0, gsf_last_failed = NULL WHERE gsf_login = ?"; + $sql = "UPDATE gems__users SET gsu_failed_logins = 0, gsu_last_failed = NULL WHERE gsu_login = ?"; $this->db->query($sql, array($_POST['userlogin'])); } catch (Exception $e) { // swallow exception @@ -941,7 +941,7 @@ */ try { if (isset($_POST['userlogin'])) { - $sql = "UPDATE gems__staff SET gsf_failed_logins = gsf_failed_logins + 1, gsf_last_failed = NOW() WHERE gsf_login = ?"; + $sql = "UPDATE gems__users SET gsu_failed_logins = gsu_failed_logins + 1, gsu_last_failed = NOW() WHERE gsu_login = ?"; $this->db->query($sql, array($_POST['userlogin'])); } } catch (Exception $e) { @@ -1097,12 +1097,7 @@ //If user is current user, read from session $allowedOrganizations = $this->session->allowedOrgs; } else { - //Here we read all allowed orgs for the user - $model = new MUtil_Model_TableModel('gems__organizations'); - $data = $model->load(); - foreach ($data as $org) { - $allowedOrganizations[$org['gor_id_organization']] = $org['gor_name']; - } + $allowedOrganizations = $this->db->fetchPairs("SELECT gor_id_organization, gor_name FROM gems__organizations WHERE gor_active = 1 ORDER BY gor_name"); } return $allowedOrganizations; @@ -1309,22 +1304,24 @@ * compatibility */ $select = new Zend_Db_Select($this->db); - $select->from('gems__staff', array('user_id'=>'gsf_id_user', - 'user_login'=>'gsf_login', - //don't expose the password hash - //'user_password'=>'gsf_password', - 'user_email'=>'gsf_email', - 'user_group'=>'gsf_id_primary_group', - 'user_locale'=>'gsf_iso_lang', - 'user_logout'=>'gsf_logout_on_survey')) + $select->from('gems__users', array('user_id' => 'gsu_id_user', + 'user_login' => 'gsu_login', + //don't expose the password hash + //'user_password'=>'gsu_password', + )) + ->join('gems__staff', 'gsu_id_user = gsf_id_user', array( + 'user_email'=>'gsf_email', + 'user_group'=>'gsf_id_primary_group', + 'user_locale'=>'gsf_iso_lang', + 'user_logout'=>'gsf_logout_on_survey')) ->columns(array('user_name'=>"(concat(coalesce(concat(`gems__staff`.`gsf_first_name`,_utf8' '),_utf8''),coalesce(concat(`gems__staff`.`gsf_surname_prefix`,_utf8' '),_utf8''),coalesce(`gems__staff`.`gsf_last_name`,_utf8'')))")) ->join('gems__groups', 'gsf_id_primary_group = ggp_id_group', array('user_role'=>'ggp_role')) - ->join('gems__organizations', 'gsf_id_organization = gor_id_organization', + ->join('gems__organizations', 'gsu_id_organization = gor_id_organization', array('user_organization_id'=>'gor_id_organization', 'user_organization_name'=>'gor_name')) ->where('ggp_group_active = ?', 1) ->where('gor_active = ?', 1) - ->where('gsf_active = ?', 1) - ->where('gsf_login = ?', $userName) + ->where('gsu_active = ?', 1) + ->where('gsu_login = ?', $userName) ->limit(1); //For a multi-layout project we need to select the appropriate style too @@ -1348,7 +1345,11 @@ public function passwordHash($name, $value, $new) { - return md5($value, false); + if (isset($this->project->salt)) { + return md5($this->project->salt . $value, false); + } else { + return md5($value, false); + } } /** Modified: branches/newUser/classes/MUtil/Model/DatabaseModelAbstract.php =================================================================== --- branches/newUser/classes/MUtil/Model/DatabaseModelAbstract.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/MUtil/Model/DatabaseModelAbstract.php 2011-10-27 15:37:58 UTC (rev 148) @@ -60,6 +60,11 @@ // If there exists a table containing two fields that map to these, shoot the table designer!!! /** + * @var array When specified delete() updates the selected rows with these values, instead of physically deleting the rows. + */ + protected $_deleteValues; + + /** * Child classes may technically be able or not able to add extra rows, * but the data model or specific circumstances may require a specific * instance of that class to deviate from the default. @@ -501,6 +506,21 @@ return $this; } + /** + * Adding DeleteValues means delete() updates the selected rows with these values, instead of physically deleting the rows. + * + * @param string|array $arrayOrField1 MUtil_Ra::pairs() arguments + * @param mxied $value1 + * @param string $field2 + * @param mixed $key2 + * @return MUtil_Model_TableModel + */ + public function addDeleteValues($arrayOrField1 = null, $value1 = null, $field2 = null, $key2 = null) + { + $args = MUtil_Ra::pairs(func_get_args()); + $this->_deleteValues = $args + $this->_deleteValues; + return $this; + } /** * Makes a copy for each key item in the model using $this->getKeyCopyName() @@ -521,7 +541,6 @@ return $this; } - /** * Creates a validator that checks that this value is used in no other * row in the table of the $name field, except that row itself. @@ -600,11 +619,12 @@ return $this->canCreate; } - public function getKeyCopier() - { - return $this->keyCopier; - } - + /** + * Returns the key copy name for a field. + * + * @param string $name + * @return string + */ public function getKeyCopyName($name) { return sprintf($this->keyCopier, $name); @@ -722,6 +742,22 @@ return $this; } + /** + * Setting DeleteValues means delete() updates the selected rows with these values, instead of physically deleting the rows. + * + * @param string|array $arrayOrField1 MUtil_Ra::pairs() arguments + * @param mxied $value1 + * @param string $field2 + * @param mixed $key2 + * @return MUtil_Model_TableModel + */ + public function setDeleteValues($arrayOrField1 = null, $value1 = null, $field2 = null, $key2 = null) + { + $args = MUtil_Ra::pairs(func_get_args()); + $this->_deleteValues = $args; + return $this; + } + public function setKeysToTable($keysOrTableName) { if (is_string($keysOrTableName)) { Modified: branches/newUser/classes/MUtil/Model/JoinModel.php =================================================================== --- branches/newUser/classes/MUtil/Model/JoinModel.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/MUtil/Model/JoinModel.php 2011-10-27 15:37:58 UTC (rev 148) @@ -174,39 +174,44 @@ } $filter = $this->_checkFilterUsed($filter); - $changed = 0; - foreach ($saveTables as $table_name) { - $table_filter = array(); - $delete = true; + if ($this->_deleteValues) { + MUtil_Echo::track($filter); + $changed = $this->save($this->_deleteValues, $filter, $saveTables); + } else { + $changed = 0; + foreach ($saveTables as $table_name) { + $table_filter = array(); + $delete = true; - // Find per table key filters - foreach ($this->_getKeysFor($table_name) as $key) { - if (isset($filter[$key])) { - $table_filter[$key] = $filter[$key]; - } else { - // If key values are missing, do not delete. - $delete = false; - foreach ($this->_joinFields as $source => $target) { - $found = null; + // Find per table key filters + foreach ($this->_getKeysFor($table_name) as $key) { + if (isset($filter[$key])) { + $table_filter[$key] = $filter[$key]; + } else { + // If key values are missing, do not delete. + $delete = false; + foreach ($this->_joinFields as $source => $target) { + $found = null; - if ($source === $key) { - $found = $target; - } elseif ($target == $key) { - $found = $source; + if ($source === $key) { + $found = $target; + } elseif ($target == $key) { + $found = $source; + } + if ($found && isset($filter[$found])) { + /// Found after all. + $delete = true; + $table_filter[$key] = $filter[$found]; + break; + } } - if ($found && isset($filter[$found])) { - /// Found after all. - $delete = true; - $table_filter[$key] = $filter[$found]; - break; - } } } - } - // MUtil_Echo::r($table_filter, $table_name); - if ($delete && $table_filter) { - $changed = max($changed, $this->_deleteTableData($this->_tables[$table_name], $table_filter)); + // MUtil_Echo::r($table_filter, $table_name); + if ($delete && $table_filter) { + $changed = max($changed, $this->_deleteTableData($this->_tables[$table_name], $table_filter)); + } } } @@ -239,6 +244,8 @@ * @param array $newValues The values to store for a single model item. * @param array $filter If the filter contains old key values these are used * to decide on update versus insert. + * @param array $saveTables Optional array containing the table names to save, + * otherwise the tables set to save at model level will be saved. * @return array The values as they are after saving (they may change). */ public function save(array $newValues, array $filter = null, array $saveTables = null) Modified: branches/newUser/classes/MUtil/Model/ModelAbstract.php =================================================================== --- branches/newUser/classes/MUtil/Model/ModelAbstract.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/MUtil/Model/ModelAbstract.php 2011-10-27 15:37:58 UTC (rev 148) @@ -543,13 +543,22 @@ return $href; } + /** + * Returns an array containing the currently defined keys for this + * model. + * + * When no keys are defined, the keys are derived from the model. + * + * @param boolean $reset If true, derives the key from the model. + * @return array + */ public function getKeys($reset = false) { if ((! $this->_keys) || $reset) { $keys = array(); foreach ($this->_model as $name => $info) { if (isset($info['key']) && $info['key']) { - $keys[$name] = $name; + $keys[] = $name; } } $this->setKeys($keys); @@ -1025,12 +1034,29 @@ return false; } + /** + * Sets the keys, processing the array key. + * + * When an array key is numeric MUtil_Model::REQUEST_ID is used. + * When there is more than one key a increasing number is added to + * MUtil_Model::REQUEST_ID starting with 1. + * + * String key names ar eleft as is. + * + * @param array $keys + * @return MUtil_Model_ModelAbstract (continuation pattern) + */ public function setKeys(array $keys) { $this->_keys = array(); if (count($keys) == 1) { - $this->_keys[MUtil_Model::REQUEST_ID] = reset($keys); + $name = reset($keys); + if (is_numeric(key($keys))) { + $this->_keys[MUtil_Model::REQUEST_ID] = $name; + } else { + $this->_keys[key($keys)] = $name; + } } else { $i = 1; foreach ($keys as $idx => $name) { @@ -1081,15 +1107,6 @@ return $this; } - /* appears to be not implemented or at least not functionale so removing - public function setOnLoad($name, $callableOrConstant) - - { - $this->set($name, self::SAVE_TRANSFORMER, $callableOrConstant); - return $this; - } - */ - public function setOnSave($name, $callableOrConstant) { $this->set($name, self::SAVE_TRANSFORMER, $callableOrConstant); Modified: branches/newUser/classes/MUtil/Model/TableBridgeAbstract.php =================================================================== --- branches/newUser/classes/MUtil/Model/TableBridgeAbstract.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/MUtil/Model/TableBridgeAbstract.php 2011-10-27 15:37:58 UTC (rev 148) @@ -1,33 +1,33 @@ <?php - -/** - * Copyright (c) 2011, Erasmus MC - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Erasmus MC nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - + /** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** * @author Matijs de Jong * @since 1.0 * @version 1.1 @@ -39,7 +39,7 @@ protected $model; protected $modelKeys; protected $repeater; - + /** * The actual table * @@ -231,9 +231,9 @@ /** * Set the model to use in the tablebridge - * + * * @param MUtil_Model_ModelAbstract $model - * @return MUtil_Model_TableBridgeAbstract + * @return MUtil_Model_TableBridgeAbstract */ public function setModel(MUtil_Model_ModelAbstract $model) { Modified: branches/newUser/classes/MUtil/Model/TableModel.php =================================================================== --- branches/newUser/classes/MUtil/Model/TableModel.php 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/classes/MUtil/Model/TableModel.php 2011-10-27 15:37:58 UTC (rev 148) @@ -47,11 +47,6 @@ class MUtil_Model_TableModel extends MUtil_Model_DatabaseModelAbstract { /** - * @var array When specified delete() updates the selected rows with these values, instead of physically deleting the rows. - */ - protected $_deleteValues; - - /** * * @var Zend_Db_Table_Abstract */ @@ -73,22 +68,6 @@ } /** - * Adding DeleteValues means delete() updates the selected rows with these values, instead of physically deleting the rows. - * - * @param string|array $arrayOrField1 MUtil_Ra::pairs() arguments - * @param mxied $value1 - * @param string $field2 - * @param mixed $key2 - * @return MUtil_Model_TableModel - */ - public function addDeleteValues($arrayOrField1 = null, $value1 = null, $field2 = null, $key2 = null) - { - $args = MUtil_Ra::pairs(func_get_args()); - $this->_deleteValues = $args + $this->_deleteValues; - return $this; - } - - /** * Delete items from the model * * @param mixed $filter True to use the stored filter, array to specify a different filter @@ -113,16 +92,6 @@ } /** - * Returns the DeleteValues used to update selected rows on delete. - * - * @return array|null - */ - public function getDeleteValues() - { - return $this->_deleteValues; - } - - /** * Returns a Zend_Db_Table_Select object to work with * * @return Zend_Db_Table_Select @@ -138,26 +107,18 @@ } } + /** + * Save a single model item. + * + * @param array $newValues The values to store for a single model item. + * @param array $filter If the filter contains old key values these are used + * to decide on update versus insert. + * @return array The values as they are after saving (they may change). + */ public function save(array $newValues, array $filter = null) { // $this->_saveTableData returns the new row values, including any automatic changes. // add $newValues to throw nothing away. return $this->_saveTableData($this->_table, $newValues, $filter) + $newValues; } - - /** - * Setting DeleteValues means delete() updates the selected rows with these values, instead of physically deleting the rows. - * - * @param string|array $arrayOrField1 MUtil_Ra::pairs() arguments - * @param mxied $value1 - * @param string $field2 - * @param mixed $key2 - * @return MUtil_Model_TableModel - */ - public function setDeleteValues($arrayOrField1 = null, $value1 = null, $field2 = null, $key2 = null) - { - $args = MUtil_Ra::pairs(func_get_args()); - $this->_deleteValues = $args; - return $this; - } } Modified: branches/newUser/configs/db/patches.sql =================================================================== --- branches/newUser/configs/db/patches.sql 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/configs/db/patches.sql 2011-10-27 15:37:58 UTC (rev 148) @@ -221,9 +221,9 @@ INSERT INTO gems__users (gsu_id_user, gsu_login, gsu_id_organization, gsu_user_class, gsu_active, gsu_password, gsu_failed_logins, gsu_last_failed, gsu_reset_key, gsu_reset_requested, gsu_reset_required, gsu_changed, gsu_changed_by, gsu_created, gsu_created_by) - SELECT grs_id_user, gr2o_patient_nr, gr2o_id_organization, 'RespondentUser', CASE WHEN gr2o_reception_code = 'OK' THEN 1 ELSE 0 END, - NULL, 0, NULL, NULL, NULL, 0, - gr2o_changed, gr2o_changed_by, gr2o_created, gr2o_created_by - FROM gems__respondents INNER JOIN gems__respondent2org ON grs_id_user = gr2o_id_user - INNER JOIN gems__organizations ON gr2o_id_organization = gor_id_organization - WHERE gor_name = 'HCU / Xpert Clinic'; + SELECT gsf_id_user, gsf_login, gsf_id_organization, 'StaffUser', gsf_active, + NULL, gsf_failed_logins, gsf_last_failed, gsf_reset_key, 0, 1, + gsf_changed, gsf_changed_by, gsf_created, gsf_created_by + FROM gems__staff; + +ALTER TABLE `gems__staff` CHANGE `gsf_id_user` `gsf_id_user` BIGINT( 20 ) UNSIGNED NOT NULL; Modified: branches/newUser/configs/db/tables/gems__staff.20.sql =================================================================== --- branches/newUser/configs/db/tables/gems__staff.20.sql 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/configs/db/tables/gems__staff.20.sql 2011-10-27 15:37:58 UTC (rev 148) @@ -2,20 +2,23 @@ -- Table containing the project staff -- CREATE TABLE if not exists gems__staff ( - gsf_id_user bigint unsigned not null auto_increment, + gsf_id_user bigint unsigned not null references gems__users (gsu_id_user), + -- depreciated gsf_login varchar(20) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null unique key, gsf_password varchar(32) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null, - gsf_active boolean not null default 1, gsf_failed_logins int(11) unsigned not null default 0, gsf_last_failed timestamp null, + gsf_id_organization bigint not null + references gems__organizations (gor_id_organization), + -- end depreciated + + gsf_id_primary_group bigint unsigned references gems__groups (ggp_id_group), - gsf_id_organization bigint not null - references gems__organizations (gor_id_organization), gsf_iso_lang char(2) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null default 'nl' references gems__languages (gml_iso_lang), gsf_logout_on_survey boolean not null default 0, Modified: branches/newUser/configs/db/tables/gems__users.10.sql =================================================================== --- branches/newUser/configs/db/tables/gems__users.10.sql 2011-10-27 13:29:59 UTC (rev 147) +++ branches/newUser/configs/db/tables/gems__users.10.sql 2011-10-27 15:37:58 UTC (rev 148) @@ -3,9 +3,9 @@ -- CREATE TABLE if not exists gems__users ( gsu_id_user bigint unsigned not null, + gsu_id_organization bigint not null references gems__organizations (gor_id_organization), gsu_login varchar(30) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null, - gsu_id_o... [truncated message content] |
From: <gem...@li...> - 2011-10-27 15:49:55
|
Revision: 149 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=149&view=rev Author: matijsdejong Date: 2011-10-27 15:49:44 +0000 (Thu, 27 Oct 2011) Log Message: ----------- Some final fixes for creating staff users and deleting items Modified Paths: -------------- branches/newUser/classes/Gems/Default/StaffAction.php branches/newUser/classes/MUtil/Model/JoinModel.php branches/newUser/configs/db/patches.sql Modified: branches/newUser/classes/Gems/Default/StaffAction.php =================================================================== --- branches/newUser/classes/Gems/Default/StaffAction.php 2011-10-27 15:37:58 UTC (rev 148) +++ branches/newUser/classes/Gems/Default/StaffAction.php 2011-10-27 15:49:44 UTC (rev 149) @@ -105,6 +105,7 @@ $bridge->addHidden( 'gsu_id_user'); $bridge->addHidden( 'gsf_id_user'); // Needed for e-mail validation + $bridge->addHidden( 'gsu_user_class'); $bridge->addText( 'gsu_login', 'size', 15, 'minlength', 4, 'validator', $model->createUniqueValidator('gsu_login')); @@ -191,6 +192,7 @@ $model->set('gsf_gender', 'label', $this->_('Gender'), 'multiOptions', $this->util->getTranslated()->getGenders()); if ($detailed) { + $model->set('gsu_user_class', 'default', 'StaffUser'); $model->set('gsf_iso_lang', 'label', $this->_('Language'), 'multiOptions', $this->util->getLocalized()->getLanguages()); $model->set('gsf_logout_on_survey', 'label', $this->_('Logout on survey'), 'multiOptions', $this->util->getTranslated()->getYesNo()); } Modified: branches/newUser/classes/MUtil/Model/JoinModel.php =================================================================== --- branches/newUser/classes/MUtil/Model/JoinModel.php 2011-10-27 15:37:58 UTC (rev 148) +++ branches/newUser/classes/MUtil/Model/JoinModel.php 2011-10-27 15:49:44 UTC (rev 149) @@ -175,8 +175,7 @@ $filter = $this->_checkFilterUsed($filter); if ($this->_deleteValues) { - MUtil_Echo::track($filter); - $changed = $this->save($this->_deleteValues, $filter, $saveTables); + $changed = $this->save($this->_deleteValues + $filter, $filter, $saveTables); } else { $changed = 0; foreach ($saveTables as $table_name) { Modified: branches/newUser/configs/db/patches.sql =================================================================== --- branches/newUser/configs/db/patches.sql 2011-10-27 15:37:58 UTC (rev 148) +++ branches/newUser/configs/db/patches.sql 2011-10-27 15:49:44 UTC (rev 149) @@ -227,3 +227,5 @@ FROM gems__staff; ALTER TABLE `gems__staff` CHANGE `gsf_id_user` `gsf_id_user` BIGINT( 20 ) UNSIGNED NOT NULL; + +ALTER TABLE `gems__staff` DROP INDEX `gsf_login`; \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-27 15:56:03
|
Revision: 150 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=150&view=rev Author: matijsdejong Date: 2011-10-27 15:55:57 +0000 (Thu, 27 Oct 2011) Log Message: ----------- Last change merged Modified Paths: -------------- branches/newUser/classes/Gems/Tracker/Source/LimeSurvey1m9FieldMap.php Property Changed: ---------------- branches/newUser/ Property changes on: branches/newUser ___________________________________________________________________ Modified: svn:mergeinfo - /trunk/library:114-122,125-139,142-144 + /trunk/library:114-122,125-139,142-144,147 Modified: branches/newUser/classes/Gems/Tracker/Source/LimeSurvey1m9FieldMap.php =================================================================== --- branches/newUser/classes/Gems/Tracker/Source/LimeSurvey1m9FieldMap.php 2011-10-27 15:49:44 UTC (rev 149) +++ branches/newUser/classes/Gems/Tracker/Source/LimeSurvey1m9FieldMap.php 2011-10-27 15:55:57 UTC (rev 150) @@ -59,6 +59,11 @@ protected $_titlesMap; /** + * @var Zend_Cache_Core + */ + protected $cache; + + /** * The language of this fieldmap * * @var string @@ -108,6 +113,7 @@ $this->lsDb = $lsDb; $this->translate = $translate; $this->tablePrefix = $tablePrefix; + $this->cache = GemsEscort::getInstance()->cache; //Load the cache from escort } /** @@ -198,7 +204,9 @@ protected function _getMap() { - if (! $this->_fieldMap) { + $cacheId = 'lsFieldMap'.$this->sourceSurveyId.$this->language; + + if( ($this->_fieldMap = $this->cache->load($cacheId)) === false ) { $gTable = $this->_getGroupsTableName(); $qTable = $this->_getQuestionsTableName(); @@ -333,9 +341,10 @@ } } $this->_fieldMap = $map; - // MUtil_Echo::track($this->_fieldMap); + $this->cache->save($this->_fieldMap, $cacheId); } + return $this->_fieldMap; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-28 10:54:48
|
Revision: 152 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=152&view=rev Author: matijsdejong Date: 2011-10-28 10:54:42 +0000 (Fri, 28 Oct 2011) Log Message: ----------- Fixes for #31 Modified Paths: -------------- branches/newUser/classes/Gems/Default/IndexAction.php branches/newUser/configs/db/patches.sql Modified: branches/newUser/classes/Gems/Default/IndexAction.php =================================================================== --- branches/newUser/classes/Gems/Default/IndexAction.php 2011-10-27 16:21:42 UTC (rev 151) +++ branches/newUser/classes/Gems/Default/IndexAction.php 2011-10-28 10:54:42 UTC (rev 152) @@ -209,9 +209,9 @@ $adapter->setIdentity($userid); $adapter->setCredential(md5($_POST['password'], false)); $result = $auth->authenticate($adapter, $_POST['userlogin']); - MUtil_Echo::track('old autho'); + // MUtil_Echo::track('old autho'); } else { - MUtil_Echo::track('new autho'); + // MUtil_Echo::track('new autho'); } if (!$result->isValid()) { Modified: branches/newUser/configs/db/patches.sql =================================================================== --- branches/newUser/configs/db/patches.sql 2011-10-27 16:21:42 UTC (rev 151) +++ branches/newUser/configs/db/patches.sql 2011-10-28 10:54:42 UTC (rev 152) @@ -228,4 +228,8 @@ ALTER TABLE `gems__staff` CHANGE `gsf_id_user` `gsf_id_user` BIGINT( 20 ) UNSIGNED NOT NULL; -ALTER TABLE `gems__staff` DROP INDEX `gsf_login`; \ No newline at end of file +ALTER TABLE `gems__staff` DROP INDEX `gsf_login`; + +ALTER TABLE `gems__staff` CHANGE `gsf_login` `gsf_login` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + CHANGE `gsf_password` `gsf_password` VARCHAR( 32 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + CHANGE `gsf_id_organization` `gsf_id_organization` BIGINT( 20 ) NULL DEFAULT NULL; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-28 12:37:03
|
Revision: 153 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=153&view=rev Author: matijsdejong Date: 2011-10-28 12:36:57 +0000 (Fri, 28 Oct 2011) Log Message: ----------- AddTrackSnippet can now handle organization switches correctly. Made it easier to write your own AnswerModel. Modified Paths: -------------- branches/newUser/snippets/AddTracksSnippet.php branches/newUser/snippets/AnswerModelSnippet.php branches/newUser/snippets/TrackAnswersModelSnippet.php Added Paths: ----------- branches/newUser/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php Added: branches/newUser/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php =================================================================== --- branches/newUser/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php (rev 0) +++ branches/newUser/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php 2011-10-28 12:36:57 UTC (rev 153) @@ -0,0 +1,229 @@ +<?php + +/** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * @package Gems + * @subpackage Tracker + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: AnswerModelSnippet.php 28 2011-09-16 06:24:15Z mennodekker $ + */ + +/** + * Displays answers to a survey. + * + * @package Gems + * @subpackage Tracker + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5 + */ +class Gems_Tracker_Snippets_AnswerModelSnippetGeneric extends Gems_Snippets_ModelTableSnippetAbstract +{ + /** + * Set a fixed model sort. + * + * Leading _ means not overwritten by sources. + * + * @var array + */ + protected $_fixedSort = array('gto_round_order' => SORT_ASC); + + /** + * Shortfix to add class attribute + * + * @var string + */ + protected $class = 'browser'; + + /** + * + * @var string Format used for displaying dates. + */ + protected $dateFormat = Zend_Date::DATE_MEDIUM; + + /** + * Required + * + * @var Gems_Loader + */ + protected $loader; + + /** + * Required + * + * @var Zend_Locale + */ + protected $locale; + + /** + * Optional: $request or $tokenData must be set + * + * The display data of the token shown + * + * @var Gems_Tracker_Token + */ + protected $token; + + /** + * Required: id of the selected token to show + * + * @var string + */ + protected $tokenId; + + /** + * Adds columns from the model to the bridge that creates the browse table. + * + * Overrule this function to add different columns to the browse table, without + * having to recode the core table building code. + * + * @param MUtil_Model_TableBridge $bridge + * @param MUtil_Model_ModelAbstract $model + * @return void + */ + protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) + { + $br = MUtil_Html::create('br'); + $selectedClass = MUtil_Lazy::iff(MUtil_Lazy::comp($bridge->gto_id_token, '==', $this->tokenId), 'selectedColumn', null); + + $bridge->th($this->_('Status')); + $td = $bridge->tdh(MUtil_Lazy::first($bridge->grc_description, $this->_('OK'))); + $td->appendAttrib('class', $selectedClass); + + $bridge->th($this->_('Question')); + $td = $bridge->tdh( + $bridge->gto_round_description, + MUtil_Lazy::iif($bridge->gto_round_description, $br), + MUtil_Lazy::iif($bridge->gto_completion_time, $bridge->gto_completion_time, $bridge->gto_valid_from) + ); + $td->appendAttrib('class', $selectedClass); + $td->appendAttrib('class', $bridge->row_class); + + foreach($model->getItemsOrdered() as $name) { + if ($label = $model->get($name, 'label')) { + $bridge->thd($label, array('class' => $model->get($name, 'thClass'))); + $td = $bridge->td($bridge->$name); + + $td->appendAttrib('class', 'answer'); + $td->appendAttrib('class', $selectedClass); + $td->appendAttrib('class', $bridge->row_class); + } + } + + $bridge->th($this->_('Token')); + $td = $bridge->tdh($bridge->gto_id_token->strtoupper()); + $td->appendAttrib('class', $selectedClass); + $td->appendAttrib('class', $bridge->row_class); + } + + /** + * Creates the model + * + * @return MUtil_Model_ModelAbstract + */ + protected function createModel() + { + $model = $this->token->getSurveyAnswerModel($this->locale->getLanguage()); + + $model->set('gto_valid_from', 'dateFormat', $this->dateFormat); + $model->set('gto_completion_time', 'dateFormat', $this->dateFormat); + + return $model; + } + + + /** + * Create the snippets content + * + * This is a stub function either override getHtmlOutput() or override render() + * + * @param Zend_View_Abstract $view Just in case it is needed here + * @return MUtil_Html_HtmlInterface Something that can be rendered + */ + public function getHtmlOutput(Zend_View_Abstract $view) + { + $htmlDiv = MUtil_Html::create()->div(); + + if ($this->tokenId) { + if ($this->token->exists) { + $htmlDiv->h3(sprintf($this->_('%s answers for patient number %s'), $this->token->getSurveyName(), $this->token->getPatientNumber())); + + $htmlDiv->pInfo(sprintf( + $this->_('Answers for token %s, patient number %s: %s.'), + strtoupper($this->tokenId), + $this->token->getPatientNumber(), + $this->token->getRespondentName())) + ->appendAttrib('class', 'noprint'); + + $table = parent::getHtmlOutput($view); + $table->setPivot(true, 2, 1); + + $this->applyHtmlAttributes($table); + $htmlDiv[] = $table; + + } else { + $htmlDiv->ul(sprintf($this->_('Token %s not found.'), $this->tokenId), array('class' => 'errors')); + } + + } else { + $htmlDiv->ul($this->_('No token specified.'), array('class' => 'errors')); + } + + $buttonDiv = $htmlDiv->buttonDiv(); + $buttonDiv->actionLink(array(), $this->_('Close'), array('onclick' => 'window.close();')); + $buttonDiv->actionLink(array(), $this->_('Print'), array('onclick' => 'window.print();')); + return $htmlDiv; + } + + /** + * The place to check if the data set in the snippet is valid + * to generate the snippet. + * + * When invalid data should result in an error, you can throw it + * here but you can also perform the check in the + * checkRegistryRequestsAnswers() function from the + * {@see MUtil_Registry_TargetInterface}. + * + * @return boolean + */ + public function hasHtmlOutput() + { + if (! $this->tokenId) { + if (isset($this->token)) { + $this->tokenId = $this->token->getTokenId(); + } + } elseif (! $this->token) { + $this->token = $this->loader->getTracker()->getToken($this->tokenId); + } + + // Output always true, returns an error message as html when anything is wrong + return true; + } +} Modified: branches/newUser/snippets/AddTracksSnippet.php =================================================================== --- branches/newUser/snippets/AddTracksSnippet.php 2011-10-28 10:54:42 UTC (rev 152) +++ branches/newUser/snippets/AddTracksSnippet.php 2011-10-28 12:36:57 UTC (rev 153) @@ -103,10 +103,11 @@ throw new exception('Invalid track type requested.'); } - $trackTypeTime = $trackType . '_time'; + $trackTypeCache = $trackType . '_' . $this->session->user_style; + $trackTypeTime = $trackType . '_time'; - if (isset($this->session->$trackType, $this->session->$trackTypeTime) && (time() < $this->session->$trackTypeTime)) { - $tracks = $this->session->$trackType; + if (isset($this->session->$trackTypeCache, $this->session->$trackTypeTime) && (time() < $this->session->$trackTypeTime)) { + $tracks = $this->session->$trackTypeCache; } else { $organization_id = $this->escort->getCurrentOrganization(); switch ($trackType) { @@ -153,8 +154,8 @@ } $tracks = $this->db->fetchPairs($sql); - $this->session->$trackType = $tracks; - $this->session->$trackTypeTime = time() + 600; + $this->session->$trackTypeCache = $tracks; + $this->session->$trackTypeTime = time() + 600; } $div = MUtil_Html::create()->div(array('class' => 'toolbox')); Modified: branches/newUser/snippets/AnswerModelSnippet.php =================================================================== --- branches/newUser/snippets/AnswerModelSnippet.php 2011-10-28 10:54:42 UTC (rev 152) +++ branches/newUser/snippets/AnswerModelSnippet.php 2011-10-28 12:36:57 UTC (rev 153) @@ -44,186 +44,5 @@ * @license New BSD License * @since Class available since version 1.4 */ -class AnswerModelSnippet extends Gems_Snippets_ModelTableSnippetAbstract -{ - /** - * Set a fixed model sort. - * - * Leading _ means not overwritten by sources. - * - * @var array - */ - protected $_fixedSort = array('gto_round_order' => SORT_ASC); - - /** - * Shortfix to add class attribute - * - * @var string - */ - protected $class = 'browser'; - - /** - * - * @var string Format used for displaying dates. - */ - protected $dateFormat = Zend_Date::DATE_MEDIUM; - - /** - * Required - * - * @var Gems_Loader - */ - protected $loader; - - /** - * Required - * - * @var Zend_Locale - */ - protected $locale; - - /** - * Optional: $request or $tokenData must be set - * - * The display data of the token shown - * - * @var Gems_Tracker_Token - */ - protected $token; - - /** - * Required: id of the selected token to show - * - * @var string - */ - protected $tokenId; - - /** - * Adds columns from the model to the bridge that creates the browse table. - * - * Overrule this function to add different columns to the browse table, without - * having to recode the core table building code. - * - * @param MUtil_Model_TableBridge $bridge - * @param MUtil_Model_ModelAbstract $model - * @return void - */ - protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) - { - $br = MUtil_Html::create('br'); - $selectedClass = MUtil_Lazy::iff(MUtil_Lazy::comp($bridge->gto_id_token, '==', $this->tokenId), 'selectedColumn', null); - - $bridge->th($this->_('Status')); - $td = $bridge->tdh(MUtil_Lazy::first($bridge->grc_description, $this->_('OK'))); - $td->appendAttrib('class', $selectedClass); - - $bridge->th($this->_('Question')); - $td = $bridge->tdh( - $bridge->gto_round_description, - MUtil_Lazy::iif($bridge->gto_round_description, $br), - MUtil_Lazy::iif($bridge->gto_completion_time, $bridge->gto_completion_time, $bridge->gto_valid_from) - ); - $td->appendAttrib('class', $selectedClass); - $td->appendAttrib('class', $bridge->row_class); - - foreach($model->getItemsOrdered() as $name) { - if ($label = $model->get($name, 'label')) { - $bridge->thd($label, array('class' => $model->get($name, 'thClass'))); - $td = $bridge->td($bridge->$name); - - $td->appendAttrib('class', 'answer'); - $td->appendAttrib('class', $selectedClass); - $td->appendAttrib('class', $bridge->row_class); - } - } - - $bridge->th($this->_('Token')); - $td = $bridge->tdh($bridge->gto_id_token->strtoupper()); - $td->appendAttrib('class', $selectedClass); - $td->appendAttrib('class', $bridge->row_class); - } - - /** - * Creates the model - * - * @return MUtil_Model_ModelAbstract - */ - protected function createModel() - { - $model = $this->token->getSurveyAnswerModel($this->locale->getLanguage()); - - $model->set('gto_valid_from', 'dateFormat', $this->dateFormat); - $model->set('gto_completion_time', 'dateFormat', $this->dateFormat); - - return $model; - } - - - /** - * Create the snippets content - * - * This is a stub function either override getHtmlOutput() or override render() - * - * @param Zend_View_Abstract $view Just in case it is needed here - * @return MUtil_Html_HtmlInterface Something that can be rendered - */ - public function getHtmlOutput(Zend_View_Abstract $view) - { - $htmlDiv = MUtil_Html::create()->div(); - - if ($this->tokenId) { - if ($this->token->exists) { - $htmlDiv->h3(sprintf($this->_('%s answers for patient number %s'), $this->token->getSurveyName(), $this->token->getPatientNumber())); - - $htmlDiv->pInfo(sprintf( - $this->_('Answers for token %s, patient number %s: %s.'), - strtoupper($this->tokenId), - $this->token->getPatientNumber(), - $this->token->getRespondentName())) - ->appendAttrib('class', 'noprint'); - - $table = parent::getHtmlOutput($view); - $table->setPivot(true, 2, 1); - - $this->applyHtmlAttributes($table); - $htmlDiv[] = $table; - - } else { - $htmlDiv->ul(sprintf($this->_('Token %s not found.'), $this->tokenId), array('class' => 'errors')); - } - - } else { - $htmlDiv->ul($this->_('No token specified.'), array('class' => 'errors')); - } - - $buttonDiv = $htmlDiv->buttonDiv(); - $buttonDiv->actionLink(array(), $this->_('Close'), array('onclick' => 'window.close();')); - $buttonDiv->actionLink(array(), $this->_('Print'), array('onclick' => 'window.print();')); - return $htmlDiv; - } - - /** - * The place to check if the data set in the snippet is valid - * to generate the snippet. - * - * When invalid data should result in an error, you can throw it - * here but you can also perform the check in the - * checkRegistryRequestsAnswers() function from the - * {@see MUtil_Registry_TargetInterface}. - * - * @return boolean - */ - public function hasHtmlOutput() - { - if (! $this->tokenId) { - if (isset($this->token)) { - $this->tokenId = $this->token->getTokenId(); - } - } elseif (! $this->token) { - $this->token = $this->loader->getTracker()->getToken($this->tokenId); - } - - // Output always true, returns an error message as html when anything is wrong - return true; - } -} +class AnswerModelSnippet extends Gems_Tracker_Snippets_AnswerModelSnippetGeneric +{ } Modified: branches/newUser/snippets/TrackAnswersModelSnippet.php =================================================================== --- branches/newUser/snippets/TrackAnswersModelSnippet.php 2011-10-28 10:54:42 UTC (rev 152) +++ branches/newUser/snippets/TrackAnswersModelSnippet.php 2011-10-28 12:36:57 UTC (rev 153) @@ -36,8 +36,6 @@ * @version $Id$ */ -include_once(dirname(__FILE__) . '/AnswerModelSnippet.php'); - /** * Class description of TrackAnswersModelSnippet * @@ -47,7 +45,7 @@ * @license New BSD License * @since Class available since version 1.4 */ -class TrackAnswersModelSnippet extends AnswerModelSnippet +class TrackAnswersModelSnippet extends Gems_Tracker_Snippets_AnswerModelSnippetGeneric { /** * Overrule to implement snippet specific filtering and sorting. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |