[geeklog-cvs] geeklog: Keep track of the user id for submitted events (bug #00...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sat Oct 3 08:51:22 EDT 2009


details:   http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/3e03947c0624
changeset: 7344:3e03947c0624
user:      Dirk Haun <dirk at haun-online.de>
date:      Sat Oct 03 11:46:54 2009 +0200
description:
Keep track of the user id for submitted events (bug #0000993)

diffstat:

 plugins/calendar/autoinstall.php             |  10 ++++-
 plugins/calendar/functions.inc               |  62 +++++++++++++++++++++++--------
 plugins/calendar/sql/mssql_install.php       |   5 +-
 plugins/calendar/sql/mssql_updates.php       |  43 +++++++++++++++++++++
 plugins/calendar/sql/mysql_install.php       |   3 +-
 plugins/calendar/sql/mysql_updates.php       |  43 +++++++++++++++++++++
 public_html/admin/plugins/calendar/index.php |   4 +-
 public_html/docs/history                     |   4 +-
 8 files changed, 151 insertions(+), 23 deletions(-)

diffs (truncated from 313 to 300 lines):

diff -r be90f91ee74f -r 3e03947c0624 plugins/calendar/autoinstall.php
--- a/plugins/calendar/autoinstall.php	Sat Oct 03 10:57:31 2009 +0200
+++ b/plugins/calendar/autoinstall.php	Sat Oct 03 11:46:54 2009 +0200
@@ -8,7 +8,7 @@
 // |                                                                           |
 // | This file provides helper functions for the automatic plugin install.     |
 // +---------------------------------------------------------------------------+
-// | Copyright (C) 2008 by the following authors:                              |
+// | Copyright (C) 2008-2009 by the following authors:                         |
 // |                                                                           |
 // | Authors: Dirk Haun         - dirk AT haun-online DOT de                   |
 // +---------------------------------------------------------------------------+
@@ -29,6 +29,12 @@
 // |                                                                           |
 // +---------------------------------------------------------------------------+
 
+/**
+* Calendar plugin automatic plugin install
+*
+* @package Calendar
+*/
+
 function plugin_autoinstall_calendar($pi_name)
 {
     $pi_name         = 'calendar';
@@ -38,7 +44,7 @@
     $info = array(
         'pi_name'         => $pi_name,
         'pi_display_name' => $pi_display_name,
-        'pi_version'      => '1.1.0',
+        'pi_version'      => '1.1.1',
         'pi_gl_version'   => '1.6.0',
         'pi_homepage'     => 'http://www.geeklog.net/'
     );
diff -r be90f91ee74f -r 3e03947c0624 plugins/calendar/functions.inc
--- a/plugins/calendar/functions.inc	Sat Oct 03 10:57:31 2009 +0200
+++ b/plugins/calendar/functions.inc	Sat Oct 03 11:46:54 2009 +0200
@@ -34,6 +34,12 @@
 // |                                                                           |
 // +---------------------------------------------------------------------------+
 
+/**
+* Implementation of the Plugin API for the Calendar plugin
+*
+* @package Calendar
+*/
+
 if (strpos(strtolower($_SERVER['PHP_SELF']), 'functions.inc') !== false) {
     die('This file can not be used on its own.');
 }
@@ -342,7 +348,7 @@
     return array (
         'eid',
         $_TABLES['events'],
-        "eid,title,description,location,address1,address2,city,state,zipcode,datestart,timestart,dateend,timeend,url",
+        "eid,title,description,location,address1,address2,city,state,zipcode,datestart,timestart,dateend,timeend,url,owner_id",
         $_TABLES['eventsubmission']
     );
 }
@@ -359,25 +365,25 @@
 * @return     string       Any wanted HTML output
 *
 */
-function plugin_moderationapprove_calendar ($id)
+function plugin_moderationapprove_calendar($id)
 {
     global $_CA_CONF, $_GROUPS, $_TABLES, $_USER;
 
-    $A = array ();
-    SEC_setDefaultPermissions ($A, $_CA_CONF['default_permissions']);
+    // The eventsubmission table only keeps track of the submitter's uid,
+    // but not of grous and permissions. So set those to sensible defaults.
 
-    // Since the eventsubmission table does not contain fields for the owner
-    // and group, we set those to the current user. Also set the default
-    // permissions as specified in the plugin's configuration
-    if (isset ($_GROUPS['Calendar Admin'])) {
+    if (isset($_GROUPS['Calendar Admin'])) {
         $group_id = $_GROUPS['Calendar Admin'];
     } else {
-        $group_id = SEC_getFeatureGroup ('calendar.moderate');
+        $group_id = SEC_getFeatureGroup('calendar.moderate');
     }
-    DB_query ("UPDATE {$_TABLES['events']} SET owner_id = '{$_USER['uid']}',"
-             ."group_id = '$group_id',perm_owner = {$A['perm_owner']}, "
-             ."perm_group = {$A['perm_group']}, perm_members = {$A['perm_members']},"
-             ."perm_anon = {$A['perm_anon']} WHERE eid = $id");
+
+    $A = array();
+    SEC_setDefaultPermissions($A, $_CA_CONF['default_permissions']);
+
+    DB_query("UPDATE {$_TABLES['events']} SET group_id = '$group_id', perm_owner = '{$A['perm_owner']}', perm_group = '{$A['perm_group']}', perm_members = '{$A['perm_members']}', perm_anon = '{$A['perm_anon']}' WHERE eid = '$id'");
+
+    return '';
 }
 
 /**
@@ -573,8 +579,8 @@
                 !SEC_hasRights('calendar.submit')) {
 
             DB_save ($_TABLES['eventsubmission'],
-                     'eid,title,event_type,url,datestart,timestart,dateend,timeend,allday,location,address1,address2,city,state,zipcode,description',
-                     "{$A['eid']},'{$A['title']}','{$A['event_type']}','{$A['url']}','{$A['datestart']}','{$A['timestart']}','{$A['dateend']}','{$A['timeend']}',{$A['allday']},'{$A['location']}','{$A['address1']}','{$A['address2']}','{$A['city']}','{$A['state']}','{$A['zipcode']}','{$A['description']}'");
+                     'eid,title,event_type,url,datestart,timestart,dateend,timeend,allday,location,address1,address2,city,state,zipcode,description,owner_id',
+                     "{$A['eid']},'{$A['title']}','{$A['event_type']}','{$A['url']}','{$A['datestart']}','{$A['timestart']}','{$A['dateend']}','{$A['timeend']}',{$A['allday']},'{$A['location']}','{$A['address1']}','{$A['address2']}','{$A['city']}','{$A['state']}','{$A['zipcode']}','{$A['description']}',{$_USER['uid']}");
 
             if (isset ($_CA_CONF['notification']) &&
                     ($_CA_CONF['notification'] == 1)) {
@@ -1440,7 +1446,7 @@
 */
 function plugin_upgrade_calendar()
 {
-    global $_CONF, $_TABLES;
+    global $_CONF, $_TABLES, $_DB_dbms;
 
     $installed_version = DB_getItem($_TABLES['plugins'], 'pi_version',
                                     "pi_name = 'calendar'");
@@ -1459,6 +1465,30 @@
     $inst_parms = plugin_autoinstall_calendar('calendar');
     $pi_gl_version = $inst_parms['info']['pi_gl_version'];
 
+    require_once $_CONF['path'] . 'plugins/calendar/sql/'
+                                . $_DB_dbms . '_updates.php';
+
+    $current_version = $installed_version;
+    $done = false;
+    while (! $done) {
+        switch ($current_version) {
+        case '1.1.0':
+            if (isset($_UPDATES[$current_version])) {
+                $_SQL = $_UPDATES[$current_version];
+                foreach ($_SQL as $sql) {
+                    DB_query($sql);
+                }
+            }
+
+            $current_version = '1.1.1';
+            break;
+
+        default:
+            $done = true;
+            break;
+        }
+    }
+
     DB_query("UPDATE {$_TABLES['plugins']} SET pi_version = '$code_version', pi_gl_version = '$pi_gl_version' WHERE pi_name = 'calendar'");
 
     return true;
diff -r be90f91ee74f -r 3e03947c0624 plugins/calendar/sql/mssql_install.php
--- a/plugins/calendar/sql/mssql_install.php	Sat Oct 03 10:57:31 2009 +0200
+++ b/plugins/calendar/sql/mssql_install.php	Sat Oct 03 11:46:54 2009 +0200
@@ -77,7 +77,8 @@
     [address1] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
     [event_type] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
     [timestart] [smalldatetime] NULL ,
-    [timeend] [smalldatetime] NULL
+    [timeend] [smalldatetime] NULL,
+    [owner_id] [numeric](8, 0) NULL
 ) ON [PRIMARY] 
 ";
 
@@ -133,7 +134,7 @@
     )  ON [PRIMARY]
 ";
 
-$_SQL[] = "INSERT INTO {$_TABLES['eventsubmission']} (eid, title, description, location, datestart, dateend, url, allday, zipcode, state, city, address2, address1, event_type, timestart, timeend) VALUES ('2008050110130162','Installed the Calendar plugin','Today, you successfully installed the Calendar plugin.','Your webserver',getdate(),getdate(),'http://www.geeklog.net/',1,NULL,NULL,NULL,NULL,NULL,'',NULL,NULL)";
+$_SQL[] = "INSERT INTO {$_TABLES['eventsubmission']} (eid, title, description, location, datestart, dateend, url, allday, zipcode, state, city, address2, address1, event_type, timestart, timeend, owner_id) VALUES ('2008050110130162','Installed the Calendar plugin','Today, you successfully installed the Calendar plugin.','Your webserver',getdate(),getdate(),'http://www.geeklog.net/',1,NULL,NULL,NULL,NULL,NULL,'',NULL,NULL,1)";
 
 $_SQL[] = "INSERT INTO {$_TABLES['blocks']} (is_enabled, name, type, title, tid, blockorder, content, onleft, phpblockfn, owner_id, group_id, perm_owner, perm_group) VALUES (1,'events_block','phpblock','Events','all',4,'',1,'phpblock_calendar',{$_USER['uid']},#group#,3,3)";
 
diff -r be90f91ee74f -r 3e03947c0624 plugins/calendar/sql/mssql_updates.php
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/calendar/sql/mssql_updates.php	Sat Oct 03 11:46:54 2009 +0200
@@ -0,0 +1,43 @@
+<?php
+
+/* Reminder: always indent with 4 spaces (no tabs). */
+// +---------------------------------------------------------------------------+
+// | Calendar Plugin 1.1                                                       |
+// +---------------------------------------------------------------------------+
+// | Upgrade SQL                                                               |
+// +---------------------------------------------------------------------------+
+// | Copyright (C) 2009 by the following authors:                              |
+// |                                                                           |
+// | Authors: Dirk Haun        - dirk AT haun-online DOT de                    |
+// +---------------------------------------------------------------------------+
+// |                                                                           |
+// | This program is licensed under the terms of the GNU General Public License|
+// | as published by the Free Software Foundation; either version 2            |
+// | of the License, or (at your option) any later version.                    |
+// |                                                                           |
+// | This program is distributed in the hope that it will be useful,           |
+// | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                      |
+// | See the GNU General Public License for more details.                      |
+// |                                                                           |
+// | You should have received a copy of the GNU General Public License         |
+// | along with this program; if not, write to the Free Software Foundation,   |
+// | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
+// |                                                                           |
+// +---------------------------------------------------------------------------+
+
+/**
+* MS SQL updates
+*
+* @package Calendar
+*/
+
+$_UPDATES = array(
+
+    '1.1.0' => array(
+        "ALTER TABLE {$_TABLES['eventsubmission']} ADD [owner_id] [numeric](8, 0) NULL AFTER timeend"
+    )
+
+);
+
+?>
diff -r be90f91ee74f -r 3e03947c0624 plugins/calendar/sql/mysql_install.php
--- a/plugins/calendar/sql/mysql_install.php	Sat Oct 03 10:57:31 2009 +0200
+++ b/plugins/calendar/sql/mysql_install.php	Sat Oct 03 11:46:54 2009 +0200
@@ -82,6 +82,7 @@
   event_type varchar(40) NOT NULL default '',
   timestart time default NULL,
   timeend time default NULL,
+  owner_id mediumint(8) unsigned NOT NULL default '1',
   PRIMARY KEY  (eid)
 ) TYPE=MyISAM
 ";
@@ -116,7 +117,7 @@
 ) TYPE=MyISAM
 ";
 
-$_SQL[] = "INSERT INTO {$_TABLES['eventsubmission']} (eid, title, description, location, datestart, dateend, url, allday, zipcode, state, city, address2, address1, event_type, timestart, timeend) VALUES ('2008050110130162','Installed the Calendar plugin','Today, you successfully installed the Calendar plugin.','Your webserver',CURDATE(),CURDATE(),'http://www.geeklog.net/',1,NULL,NULL,NULL,NULL,NULL,'',NULL,NULL)";
+$_SQL[] = "INSERT INTO {$_TABLES['eventsubmission']} (eid, title, description, location, datestart, dateend, url, allday, zipcode, state, city, address2, address1, event_type, timestart, timeend, owner_id) VALUES ('2008050110130162','Installed the Calendar plugin','Today, you successfully installed the Calendar plugin.','Your webserver',CURDATE(),CURDATE(),'http://www.geeklog.net/',1,NULL,NULL,NULL,NULL,NULL,'',NULL,NULL,1)";
 
 $_SQL[] = "INSERT INTO {$_TABLES['blocks']} (is_enabled, name, type, title, tid, blockorder, content, onleft, phpblockfn, owner_id, group_id, perm_owner, perm_group) VALUES (1,'events_block','phpblock','Events','all',4,'',1,'phpblock_calendar',{$_USER['uid']},#group#,3,3)";
 
diff -r be90f91ee74f -r 3e03947c0624 plugins/calendar/sql/mysql_updates.php
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/calendar/sql/mysql_updates.php	Sat Oct 03 11:46:54 2009 +0200
@@ -0,0 +1,43 @@
+<?php
+
+/* Reminder: always indent with 4 spaces (no tabs). */
+// +---------------------------------------------------------------------------+
+// | Calendar Plugin 1.1                                                       |
+// +---------------------------------------------------------------------------+
+// | Upgrade SQL                                                               |
+// +---------------------------------------------------------------------------+
+// | Copyright (C) 2009 by the following authors:                              |
+// |                                                                           |
+// | Authors: Dirk Haun        - dirk AT haun-online DOT de                    |
+// +---------------------------------------------------------------------------+
+// |                                                                           |
+// | This program is licensed under the terms of the GNU General Public License|
+// | as published by the Free Software Foundation; either version 2            |
+// | of the License, or (at your option) any later version.                    |
+// |                                                                           |
+// | This program is distributed in the hope that it will be useful,           |
+// | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                      |
+// | See the GNU General Public License for more details.                      |
+// |                                                                           |
+// | You should have received a copy of the GNU General Public License         |
+// | along with this program; if not, write to the Free Software Foundation,   |
+// | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
+// |                                                                           |
+// +---------------------------------------------------------------------------+
+
+/**
+* MySQL updates
+*
+* @package Calendar
+*/
+
+$_UPDATES = array(
+
+    '1.1.0' => array(
+        "ALTER TABLE {$_TABLES['eventsubmission']} ADD owner_id mediumint(8) unsigned NOT NULL default '1' AFTER timeend"
+    )
+
+);
+
+?>
diff -r be90f91ee74f -r 3e03947c0624 public_html/admin/plugins/calendar/index.php
--- a/public_html/admin/plugins/calendar/index.php	Sat Oct 03 10:57:31 2009 +0200
+++ b/public_html/admin/plugins/calendar/index.php	Sat Oct 03 11:46:54 2009 +0200
@@ -104,7 +104,9 @@
             return $retval;
         }
     } else {
-        $A['owner_id'] = $_USER['uid'];
+        if (empty($A['owner_id'])) {
+            $A['owner_id'] = $_USER['uid'];
+        }
         if (isset ($_GROUPS['Calendar Admin'])) {
             $A['group_id'] = $_GROUPS['Calendar Admin'];
         } else {
diff -r be90f91ee74f -r 3e03947c0624 public_html/docs/history
--- a/public_html/docs/history	Sat Oct 03 10:57:31 2009 +0200



More information about the geeklog-cvs mailing list