[mod] Templates owned by their Admins

3rd party code for phpList

[mod] Templates owned by their Admins

Postby Guest » 2:18am, Sun 28 Dec, 2008

What this does:

Templates are owned by their admin/s.
After you implement this code the template will be owned by their creator and the SuperAdmin.
Each admin can set one of HIS templates as HIS defualt.

If you work on any addition to the code below to include any of the ToDo tasks below or implement other improvements and additions,
kindly post here so that I can update this post.

Thanks You
Stephen Said
IdeaSoft

---------------------------------------------------------------------------------------------------
Make sure to change the table prefix below before creating the tables in your mySQL otherwise it won't work.
---------------------------------------------------------------------------------------------------

--SQL tables required.
--===================
--
-- Table structure for table `phplist_template_permissions`
-- This table holds template owners
--

CREATE TABLE `phplist_template_permissions` (
`id` int(11) NOT NULL auto_increment,
`UserID` varchar(12) NOT NULL default '',
`TemplateID` varchar(12) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

--
-- Table structure for table `phplist_template_default`
-- This table holds default template info for each admin. Only one default template per admin.
--

CREATE TABLE `phplist_template_default` (
`tdID` int(11) NOT NULL auto_increment,
`template` int(11) NOT NULL default '0',
`adminid` int(11) NOT NULL,
PRIMARY KEY (`tdID`),
UNIQUE KEY `adminid` (`adminid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

---------------------------------------------------------------------------------------------------

Files modified:
- send_core.php
- connect.php
- templates.php
- template.php

---------------------------------------------------------------------------------------------------

Changes:
connect.php
===========
Line: 94
right after:
'bounceregex_bounce' => $table_prefix . 'bounceregex_bounce',
add the following:
'template_permissions' => $table_prefix . 'template_permissions',
'template_default' => $table_prefix . 'template_default',

---------------------------------------------------------------------------------------------------

templates.php
=============
Line 3:
right after:
require_once dirname(__FILE__).'/accesscheck.php';
add this:
//get currently logged user id
$UserID = $_SESSION["logindetails"]["id"];

Line 4:
Change:
if (isset($_GET['delete'])) {
# delete the index in delete
$delete = sprintf('%d',$_GET['delete']);
print $GLOBALS['I18N']->get('Deleting')." $delete ...\n";
$result = Sql_query("delete from ".$tables["template"]." where id = $delete");
$result = Sql_query("delete from ".$tables["templateimage"]." where template = $delete");
print "... ".$GLOBALS['I18N']->get('Done')."<br /><hr /><br />\n";
}
to:
if (isset($_GET['delete'])) {
# delete the index in delete
$delete = sprintf('%d',$_GET['delete']);
print $GLOBALS['I18N']->get('Deleting')." $delete ...\n";
$result = Sql_query("delete from ".$tables["template"]." where id = $delete");
$result = Sql_query("delete from ".$tables["templateimage"]." where template = $delete");
$result = Sql_query("delete from ".$tables["template_default"]." where template = $delete"); //edit - delete default for this template
$result = Sql_query("delete from ".$tables["template_permissions"]." where TemplateID = $delete"); //edit - delete permissions for this template
print "... ".$GLOBALS['I18N']->get('Done')."<br /><hr /><br />\n";
}

Line 13:
replace:
saveConfig('defaultmessagetemplate',sprintf('%d',$_POST['defaulttemplate']));
with:
// saveConfig('defaultmessagetemplate',sprintf('%d',$_POST['defaulttemplate']));
$dt = $_POST['defaulttemplate'];
$req = Sql_Query("SELECT adminid FROM {$tables["template_default"]} WHERE adminid = '$UserID'");
if (mysql_num_rows($req)>0) {
$req = Sql_Query("UPDATE {$tables["template_default"]} SET template = '$dt' WHERE adminid = '$UserID'");
} else {
$req = Sql_Query("INSERT INTO {$tables["template_default"]} (`template`, `adminid`) VALUES ('$dt', '$UserID')");
}

Line 23:
replace:
$req = Sql_Query("select * from {$tables["template"]} order by listorder");
if (!Sql_Affected_Rows())
print '<p class="error">'.$GLOBALS['I18N']->get("No template have been defined").'</p>';

$defaulttemplate = getConfig('defaultmessagetemplate');
with:
// $req = Sql_Query("select * from {$tables["template"]} order by listorder");
$role = ($UserID > 1) ? "AND UserID = '$UserID'" : "";
$req = Sql_Query("SELECT {$tables["template"]}.id, title, template, UserID, TemplateID FROM {$tables["template"]}, {$tables["template_permissions"]} WHERE {$tables["template"]}.id = {$tables["template_permissions"]}.TemplateID $role order by listorder");
if (!Sql_Affected_Rows())
print '<p class="error">'.$GLOBALS['I18N']->get("No template have been defined").'</p>';

// $defaulttemplate = getConfig('defaultmessagetemplate');
$deftemp = Sql_Query("SELECT template FROM {$tables["template_default"]} WHERE adminid = '$UserID'");
$row = Sql_fetch_Array($deftemp);
$defaulttemplate = $row['template'];

---------------------------------------------------------------------------------------------------

send_core.php
=============
Line 72:
Replace:
if (!$id) {
$defaulttemplate = getConfig('defaultmessagetemplate');
Sql_Query(sprintf('insert into %s (subject,status,entered,sendformat,embargo,repeatuntil,owner,template,tofield,replyto)
values("(no subject)","draft",now(),"HTML",now(),now(),%d,%d,"","")',$GLOBALS["tables"]["message"],$_SESSION["logindetails"]["id"],$defaulttemplate));
$id = Sql_Insert_id();
# 0008720: Using -p send from the commandline doesn't seem to work
if(!$GLOBALS["commandline"]){
Redirect($_GET["page"]."&id=$id");
exit;
}
}
with:
if (!$id) {
$UserID = $_SESSION["logindetails"]["id"];
$deftemp = Sql_Query("SELECT template FROM {$tables["template_default"]} WHERE adminid = '$UserID'");
$row = Sql_fetch_Array($deftemp);
$defaulttemplate = $row['template'];
// $defaulttemplate = getConfig('defaultmessagetemplate');
Sql_Query(sprintf('insert into %s (subject,status,entered,sendformat,embargo,repeatuntil,owner,template,tofield,replyto)
values("(no subject)","draft",now(),"HTML",now(),now(),%d,%d,"","")',$GLOBALS["tables"]["message"],$_SESSION["logindetails"]["id"],$defaulttemplate));
$id = Sql_Insert_id();
# 0008720: Using -p send from the commandline doesn't seem to work
if(!$GLOBALS["commandline"]){
Redirect($_GET["page"]."&id=$id");
exit;
}
}

Line 1092:
Replace:
$req = Sql_Query("select id,title from {$tables["template"]} order by listorder");
if (Sql_affected_Rows()) {
$formatting_content .= '<tr><td>'.Help("usetemplate").' '.$GLOBALS['I18N']->get("usetemplate").': </td>
<td><select name="template"><option value=0>-- '.$GLOBALS['I18N']->get("selectone").'</option>';
$req = Sql_Query("select id,title from {$tables["template"]} order by listorder");
while ($row = Sql_Fetch_Array($req)) {
$formatting_content .= sprintf('<option value="%d" %s>%s</option>',$row["id"], $row["id"]==$_POST["template"]?'SELECTED':'',$row["title"]);
}
$formatting_content .= '</select></td></tr>';
}
with:
/*
$req = Sql_Query("select id,title from {$tables["template"]} order by listorder");
if (Sql_affected_Rows()) {
$formatting_content .= '<tr><td>'.Help("usetemplate").' '.$GLOBALS['I18N']->get("usetemplate").': </td>
<td><select name="template"><option value=0>-- '.$GLOBALS['I18N']->get("selectone").'</option>';
$req = Sql_Query("select id,title from {$tables["template"]} order by listorder");
while ($row = Sql_Fetch_Array($req)) {
$formatting_content .= sprintf('<option value="%d" %s>%s</option>',$row["id"], $row["id"]==$_POST["template"]?'SELECTED':'',$row["title"]);
}
$formatting_content .= '</select></td></tr>';
}
*/

$req = Sql_Query("select id,title from {$tables["template"]} order by listorder");
if (Sql_affected_Rows()) {
$formatting_content .= '<tr><td>'.Help("usetemplate").' '.$GLOBALS['I18N']->get("usetemplate").': </td>
<td><select name="template"><option value=0>-- '.$GLOBALS['I18N']->get("selectone").'</option>';

//Get current user logged in
$UserID = $_SESSION["logindetails"]["id"];

$role = ($UserID > 1) ? "AND UserID = '$UserID'" : "";

$req = Sql_Query("SELECT DISTINCT {$tables["template"]}.id, {$tables["template"]}.title FROM {$tables["template_permissions"]}, {$tables["template"]} WHERE {$tables["template"]}.id = {$tables["template_permissions"]}.TemplateID $role");
while ($row = Sql_Fetch_Array($req))
{
$formatting_content .= sprintf('<option value="%d" %s>%s</option>',$row["id"], $row["id"]==$_POST["template"]?'SELECTED':'',$row["title"]);
}
$formatting_content .= '</select></td></tr>';
}

template.php
============
Line 141
Change the following function from:
if ($templateok) {
if (!$id) {
Sql_Query("insert into {$tables["template"]} (title) values(\"$title\")");
$id = Sql_Insert_id();
}
to:
//which user is currently logged in?
$UserID = $_SESSION["logindetails"]["id"];

if ($templateok) {
if (!$id) {
Sql_Query("insert into {$tables["template"]} (title) values(\"$title\")");
$id = Sql_Insert_id();
// edit - update template permissions so that template is owned by creator
Sql_Query("insert into {$tables["template_permissions"]} (`UserID`, `TemplateID`) VALUES ('$UserID', '$id')");
// edit - update template permissions so that super admin owns the template also.
Sql_Query("insert into {$tables["template_permissions"]} (`UserID`, `TemplateID`) VALUES ('1', '$id')");
}

---------------------------------------------------------------------------------------------------

Note:
All line numbers refer to line numbers of the original files from version 2.10.8 BEFORE editing.

---------------------------------------------------------------------------------------------------

ToDo:
SuperAdmin must be able to assign a template to one or more admins
SuperAdmin must be able to set default template for admins
SuperAdmins must be able to view all templates - ready
With this module the 'defaultmessagetemplate' value in the config table is no longer requried. Can be removed.
Guest
 

Re: [mod] Templates owned by their Admins

Postby Elmarie » 6:06am, Tue 26 Jan, 2010

Hi

I tried your patch for the template permissions, but when I view the template.php and templates.php pages it's just blank. Can you maybe assist? I really need to get this working.

Thanks!
Elmarie
phpList newbie
 
Posts: 2
Joined: 9:29am, Mon 25 Jan, 2010

Re: [mod] Templates owned by their Admins

Postby boluda » 3:11pm, Sun 30 Jan, 2011

It works great for me! I'm using version 2.10.12

Thanks so much, you saved the day!

Joan
boluda
phpList newbie
 
Posts: 1
Joined: 3:07pm, Sun 30 Jan, 2011

Re: [mod] Templates owned by their Admins

Postby villosoph » 8:09pm, Tue 09 Oct, 2012

Tested with 2.10.19
now every admin can only choose his templates when sending a message - great!
villosoph
phpList newbie
 
Posts: 1
Joined: 8:05pm, Tue 09 Oct, 2012


Return to Contributions: Plug-ins, Add-ons, Mods

Who is online

Users browsing this forum: No registered users and 2 guests