Thank you for downloading jquarks.php
Your download should start in 3 seconds... If not please use the download link below
| 1 | <?php
|
|---|---|
| 2 | /**
|
| 3 | * JQuarks User Plugin |
| 4 | * |
| 5 | * @version $Id: jquarks.php 59 2010-03-02 08:40:27Z fnaccache $ |
| 6 | * @author IP-Tech Labs <labs@iptech-offshore.com> |
| 7 | * @copyright 2009-2010 IP-Tech |
| 8 | * @package JQuarks-Plugin |
| 9 | * @subpackage User |
| 10 | * @link http://www.iptechinside.com/labs/projects/show/jquarks |
| 11 | * @since 0.1 |
| 12 | * @license GNU/GPL2 |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License |
| 16 | * as published by the Free Software Foundation; version 2 |
| 17 | * of the License. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 27 | * or see <http://www.gnu.org/licenses/> |
| 28 | */ |
| 29 | |
| 30 | // Check to ensure this file is included in Joomla!
|
| 31 | defined('_JEXEC') or die( 'Restricted access' ); |
| 32 | |
| 33 | jimport('joomla.plugin.plugin');
|
| 34 | |
| 35 | class plgUserJquarks extends JPlugin |
| 36 | {
|
| 37 | /**
|
| 38 | * Constructor |
| 39 | * |
| 40 | * For php4 compatability we must not use the __constructor as a constructor for plugins |
| 41 | * because func_get_args ( void ) returns a copy of all passed arguments NOT references. |
| 42 | * This causes problems with cross-referencing necessary for the observer design pattern. |
| 43 | * |
| 44 | * @param object $subject The object to observe |
| 45 | * @param array $config An array that holds the plugin configuration |
| 46 | * @since 1.5 |
| 47 | */ |
| 48 | function plgUserJquarks(& $subject, $config)
|
| 49 | {
|
| 50 | parent::__construct($subject, $config); |
| 51 | } |
| 52 | |
| 53 | /**
|
| 54 | * Remove all affectation to quizzes for the deleted user |
| 55 | * |
| 56 | * Method is called after user data is deleted from the database |
| 57 | * |
| 58 | * @param array holds the user data |
| 59 | * @param boolean true if user was succesfully stored in the database |
| 60 | * @param string message |
| 61 | */ |
| 62 | function onAfterDeleteUser($user, $success, $msg)
|
| 63 | {
|
| 64 | if ($success)
|
| 65 | {
|
| 66 | $db = &JFactory::getDBO(); |
| 67 | |
| 68 | // getting the assignations for this user
|
| 69 | $query = 'SELECT id' .
|
| 70 | ' FROM #__jquarks_users_quizzes' .
|
| 71 | ' WHERE user_id = ' . $user['id'] ; |
| 72 | |
| 73 | $db->setQuery($query); |
| 74 | $assignations = $db->loadResultArray(); |
| 75 | |
| 76 | if (count($assignations))
|
| 77 | {
|
| 78 | //$affectationList = implode(',', $affectations) ;
|
| 79 | |
| 80 | foreach ($assignations AS $assignation)
|
| 81 | {
|
| 82 | // getting the number of sessions
|
| 83 | $query = 'SELECT count(id)' .
|
| 84 | ' FROM #__jquarks_quizsession' .
|
| 85 | ' WHERE affected_id = ' . $assignation ;
|
| 86 | |
| 87 | $db->setQuery($query) ; $db->getQuery(); //exit();
|
| 88 | |
| 89 | if ($db->loadResult())
|
| 90 | {
|
| 91 | // there are session, so we archieve the assignations
|
| 92 | //$sessionList = implode(',', $sessions) ;
|
| 93 | |
| 94 | $query = 'UPDATE #__jquarks_users_quizzes' .
|
| 95 | ' SET archived = 1' .
|
| 96 | ' WHERE id = ' . $assignation ;
|
| 97 | |
| 98 | if (! $db->Execute($query)) {
|
| 99 | return false ; |
| 100 | } |
| 101 | } |
| 102 | else
|
| 103 | {
|
| 104 | // no sessions are found we may delete the assignations
|
| 105 | $query = 'DELETE FROM #__jquarks_users_quizzes' .
|
| 106 | ' WHERE id = ' . $assignation ;
|
| 107 | |
| 108 | if (! $db->Execute($query)) {
|
| 109 | return false ; |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return true; |
| 117 | } |
| 118 | |
| 119 | /**
|
| 120 | * Add the newly created user to all public quizzes already existant |
| 121 | * |
| 122 | * Method is called after user data is deleted from the database |
| 123 | * |
| 124 | * @param array holds the user data |
| 125 | * @param boolean true if user is new |
| 126 | * @param boolean true if user was succesfully stored in the database |
| 127 | * @param string message |
| 128 | */ |
| 129 | function onAfterStoreUser($user, $isnew, $success, $msg)
|
| 130 | {
|
| 131 | if ($isnew && $success)
|
| 132 | {
|
| 133 | // case of a new user to affect to public quizzes
|
| 134 | $db = &JFactory::getDBO(); |
| 135 | |
| 136 | //getting all public quizzes
|
| 137 | $query = 'SELECT id' .
|
| 138 | ' FROM #__jquarks_quizzes';// . |
| 139 | //' WHERE access_id = 0' ;
|
| 140 | |
| 141 | $db->setQuery($query); |
| 142 | $publicQuizzes = $db->loadResultArray(); |
| 143 | |
| 144 | if (count($publicQuizzes))
|
| 145 | {
|
| 146 | foreach ($publicQuizzes AS $publicQuiz)
|
| 147 | {
|
| 148 | $query = 'INSERT INTO' .
|
| 149 | ' #__jquarks_users_quizzes' .
|
| 150 | ' (`quiz_id`, `user_id`)' .
|
| 151 | ' VALUES (' . $publicQuiz . ', ' . $user['id'] . ')' ; |
| 152 | |
| 153 | if (!$db->Execute($query)) {
|
| 154 | return false; |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | return true; |
| 161 | } |
| 162 | |
| 163 | /**
|
| 164 | * redirect logged in user to quizzes view |
| 165 | * this function prevents unvalid URL after login |
| 166 | * |
| 167 | * @global JApplication $mainframe |
| 168 | * @param array $user |
| 169 | * @param array $options |
| 170 | * @return boolean |
| 171 | */ |
| 172 | function onLoginUser($user, $options)
|
| 173 | {
|
| 174 | global $mainframe;
|
| 175 | |
| 176 | $u =& JURI::getInstance(); |
| 177 | |
| 178 | if($u->getVar("option") == 'com_jquarks') { |
| 179 | $mainframe->redirect('index.php?option=com_jquarks&view=quizzes');
|
| 180 | } |
| 181 | return true; |
| 182 | } |
| 183 | |
| 184 | /**
|
| 185 | *redirect logged out user to quizzes view |
| 186 | * this function prevents unvalid URL after logout |
| 187 | * |
| 188 | * @global JApplication $mainframe |
| 189 | * @param array $user |
| 190 | * @return boolean |
| 191 | */ |
| 192 | function onLogoutUser($user)
|
| 193 | {
|
| 194 | global $mainframe;
|
| 195 | |
| 196 | $u =& JURI::getInstance(); |
| 197 | |
| 198 | if($u->getVar("option") == 'com_jquarks') { |
| 199 | $mainframe->redirect('index.php?option=com_jquarks&view=quizzes');
|
| 200 | } |
| 201 | return true; |
| 202 | } |
| 203 | |
| 204 | } |