[mod] Template Permissions

3rd party code for phpList

[mod] Template Permissions

Postby m4rkbell » 9:39am, Mon 20 Mar, 2006

Is it possible to show/hide templates based on the admin login?
For example I have 4 administrators who send newsletters and bulletins to various groups of people, I don't wan't them being able to see - or accidentally use, each others templates.

Thanks
Mark
m4rkbell
phpList newbie
 
Posts: 3
Joined: 6:36pm, Sun 19 Mar, 2006

Postby Totto » 10:03pm, Mon 20 Mar, 2006

No admin ownership exists on templates currently, although being achieved on lists and subscribe pages.
To all forum users: Search the forums when you got a question first! Your question may have already been asked many times before and also many times answered. The search feature is your best friend on any forums of this kind!
Totto
PL Master
 
Posts: 370
Joined: 11:20pm, Tue 31 Jan, 2006

Postby m4rkbell » 7:25pm, Tue 21 Mar, 2006

Thanks Totto,

It's quite important for me, so as thats the case I thought i'd write it in - i'll post a revised version so once i've built the front end and tidied it up a little.

I've added a new table to handle UserID and TemplateID association. As a new Template is added, an Admin is assigned to it. An Admin can have as many templates as we like. When sending a new message, the 'select a template' drop down list will only show templates that we have allowed that Admin to see. Problem solved!

The new table:

Code: Select all
--
-- Table structure for table `phplist_template_permissions`
--

CREATE TABLE `phplist_template_permissions` (
  `id` int(11) NOT NULL auto_increment,
  `UserID` varchar(12) NOT NULL default '',
  `TemplateID` varchar(12) NOT NULL default '',
  `TemplateDESC` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=4 ;

--
-- Dumping data for table `phplist_template_permissions`
--

INSERT INTO `phplist_template_permissions` VALUES (1, '2', '1', 'Old Phplist design');
INSERT INTO `phplist_template_permissions` VALUES (2, '2', '2', 'PHPlist');
INSERT INTO `phplist_template_permissions` VALUES (3, '2', '3', 'new template');


And a little change to send_core.php [v2.10.2] at about line 1013

Code: Select all

#########################
#       mod to allow template permissions - 21/03/06 
#       Mark Bell                                 
#########################

//print the help '?' link and the 'Use Template' label

$formatting_content .= '<td>'.Help("usetemplate").' '.$GLOBALS['I18N']->get("usetemplate").': </td>
                        <td><select><option>-- '.$GLOBALS['I18N']->get("selectone").'</option>';

//which user is currently logged in?
$UserID = $_SESSION["logindetails"]["id"];

$req = Sql_Query("SELECT TemplateID, TemplateDESC FROM phplist_template_permissions WHERE UserID = '$UserID'");
while ($row = Sql_Fetch_Array($req)) {

$formatting_content .= sprintf('<option>%s</option>',$row["TemplateID"], $row["TemplateID"]==$_POST["template"]?'SELECTED':'',$row["TemplateDESC"]);
    }
    $formatting_content .= '</select></td></tr>';
  }

#########################
#       End - 21/03/06                         
#       Mark Bell                                 
#########################


What do you think?
Regards
Mark
Last edited by m4rkbell on 10:06am, Sat 05 May, 2007, edited 1 time in total.
m4rkbell
phpList newbie
 
Posts: 3
Joined: 6:36pm, Sun 19 Mar, 2006

Postby Totto » 9:56pm, Tue 21 Mar, 2006

Very much thanks, Mark! Nice to see someone sharing his hacks on improving the system :) That's what community could be built around

Report it as a request to mantis with a link to you source shared on this post here so Michael (the developer) to have a look at it! His opinion is what would be important here. If it don't get included into next phpList releases, it would be a bit harder to mainain as the new table should be always manually added to the DB with each new release. But as I know, Michael is working on a lot of issues currently so much improvement could be awaited soon.
Also, if bevan (the forum moderator) does not come back soon (I haven't seen a post from him for maybe already 2 weeks now, but he was very active around before), it would be good to make a new post with your final revision (and if the hacks gets proved on working fine) at the "Add-ons, Contributions, Mods, Plug-ins" forum as it is where it's place is actually.
Thx again and greetings! Keep on good working!
To all forum users: Search the forums when you got a question first! Your question may have already been asked many times before and also many times answered. The search feature is your best friend on any forums of this kind!
Totto
PL Master
 
Posts: 370
Joined: 11:20pm, Tue 31 Jan, 2006

Template permissions

Postby tasfalen » 8:53pm, Sun 17 Sep, 2006

Hey,

I'm hoping for the exact same thing, unfortunately I'm a complete MySQL and PHP newb (well not complete, but close!)

I think I successfully added the table you suggested, but when I added the php it didn't seem to do anything, and seems to have borked my install. :?

Its ok though, this is just a test install, but I'd really appreciate any assistance you can provide! his would be a GREAT feature to add.

Cheers!
tasfalen
phpList newbie
 
Posts: 1
Joined: 8:50pm, Sun 17 Sep, 2006

Postby bigbass » 8:25pm, Fri 04 May, 2007

m4rkbell,

didn't try this, but for me this is essential too, and I believe this should be in the system!!!

whoever is the guru of code, please put this option in!

I will check out your hack right now.
If it works, thank you in advance!


bassy regards,
benjamin
bigbass
phpList newbie
 
Posts: 3
Joined: 6:29pm, Wed 11 Apr, 2007

update

Postby m4rkbell » 9:07pm, Fri 04 May, 2007

I've made quite a few changes to this mod recently, i'll post up a complete version on my site over the next couple of weeks.

Cheers,
m4rkbell
phpList newbie
 
Posts: 3
Joined: 6:36pm, Sun 19 Mar, 2006

Postby okker » 1:54pm, Thu 23 Aug, 2007

I've succesfully added the table I believe, and added the extra code to send_core in te admin folder but it doesn't seem to work. I've tested it by adding a new template but I don't get the posibility to apply the template to a certain admin.

Has this got anything to do with to which line the extra code is added in send_core?

Thanx for you replies,

Irma
okker
phpLister
 
Posts: 13
Joined: 8:37am, Fri 23 Mar, 2007
Location: Netherlands

little update of the code

Postby boeloeboeloe » 3:22pm, Thu 22 Nov, 2007

Some little corrections to send_core.php [v2.10.5] at about line 1039:

Code: Select all
    #########################
   #       mod to allow template permissions - 21/03/06 - 22/11/07
   #       Mark Bell, Lode Vanoost                                 
   #########################
   
   //print the help '?' link and the 'Use Template' label
   
   $formatting_content .= '<tr><td>'.Help("usetemplate").' '.$GLOBALS['I18N']->get("usetemplate").': </td>
                  <td><select><option>-- '.$GLOBALS['I18N']->get("selectone").'</option>';
   
   //which user is currently logged in?
   $UserID = $_SESSION["logindetails"]["id"];a

   $req = Sql_Query("SELECT TemplateID, TemplateDESC FROM phplist_template_permissions WHERE UserID = '$UserID'");
   while ($row = Sql_Fetch_Array($req))
   {
      $formatting_content .= sprintf('<option>%s</option>',$row["TemplateID"], $row["TemplateID"]==$_POST["template"]?' SELECTED':'',$row["TemplateDESC"]);
   }
   $formatting_content .= '</select></td></tr>';
  }
   
   #########################
   #       End - 21/03/06 - 22/11/07           
   #       Mark Bell , Lode Vanoost                               
   #########################
boeloeboeloe
phpList newbie
 
Posts: 1
Joined: 3:15pm, Thu 22 Nov, 2007

Postby divinity » 6:02am, Fri 02 May, 2008

NOTE: The forum is stripping code from what I've posted below, so use the attached file to get the correct code.

Update to code for 2.10.5. Allows the superadmins to see all templates while restricting all others.

First, need to add a new field to the template_permissions table to hold the role for the template owner. Be sure to either remove or rename the table based on whether you used a prefix or not.

Code: Select all
CREATE TABLE `phplist_template_permissions` (
  `id` int(11) NOT NULL auto_increment,
  `UserID` varchar(12) NOT NULL default '',
  `UserRole` int(11) NOT NULL,
  `TemplateID` varchar(12) NOT NULL default '',
  `TemplateDESC` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT

--
-- Dumping data for table `phplist_template_permissions`
--

INSERT INTO `phplist_template_permissions` VALUES (1, 1, '2', '1', 'Template Name 1');
INSERT INTO `phplist_template_permissions` VALUES (2, 0, '2', '2', 'Template Name 2');
INSERT INTO `phplist_template_permissions` VALUES (3, 0, '2', '3', 'Template Name 3');


Then I corrected a few items and updated the script in send_core.php.

Find this section starting at line 1037:

Code: Select all
  $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><option>-- '.$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>%s</option>',$row["id"], $row["id"]==$_POST["template"]?'SELECTED':'',$row["title"]);
    }
    $formatting_content .= '</select></td></tr>';
  }



Comment out lines to make the section appear like this:

Code: Select all
  $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><option>-- '.$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>%s</option>',$row["id"], $row["id"]==$_POST["template"]?'SELECTED':'',$row["title"]);
//    }
//    $formatting_content .= '</select></td></tr>';
//  }


Replace the commented text with the following:

Code: Select all
    #########################
   #       mod to allow template permissions - 21/03/06 - 22/11/07 - 2/5/08
   #       Mark Bell, Lode Vanoost, Lisa Jeter                                 
   #########################
   
   //print the help '?' link and the 'Use Template' label
   
   $formatting_content .= '<tr><td>'.Help("usetemplate").' '.$GLOBALS['I18N']->get("usetemplate").': </td>
         <td><select><option>-- '.$GLOBALS['I18N']->get("selectone").'</option>';
   
   //which user is currently logged in?
   $UserID = $_SESSION["logindetails"]["id"];

   $role = ($UserID > 1) ? "WHERE UserID = '$UserID'" : "";
   
   $req = Sql_Query("SELECT TemplateID, TemplateDESC FROM phplist_template_permissions $role");
   while ($row = Sql_Fetch_Array($req))
   {
      $formatting_content .= sprintf('<option>%s</option>',$row["TemplateID"], $row["TemplateID"]==$_POST["template"]?' SELECTED':'',$row["TemplateDESC"]);
   }
   $formatting_content .= '</select></td></tr>';
  }
   
   #########################
   #       End - 21/03/06 - 22/11/07 - 2/5/08         
   #       Mark Bell , Lode Vanoost, Lisa Jeter                               
   #########################   
 


Other notes not in this thread.

You will need to add new templates manually to the template_permissions table.

Edits need to be made to template.php in order for the template_permissions table to be updated. The code has to be similar to that found in editlist.php.

Hope you find this useful.
divinity
phpList newbie
 
Posts: 1
Joined: 6:47pm, Fri 25 Apr, 2008

Postby Ernesto » 5:51pm, Sun 04 May, 2008

Thanks for the updated code.

BTW, HTML Code stripping is only done if you did not check "Disable HTML in this post" when editing your forum post. You could re-edit your post and paste the code another time with this setting selected.
Search first, Ask questions later...
Ernesto
PL Freak!
 
Posts: 592
Joined: 2:25am, Thu 08 Jun, 2006

Not working

Postby solmar » 3:40pm, Fri 27 Jun, 2008

Is divinity's code correct, or the code displayed here is still messed up? Also, I cannot find the attachment.
I tried the three versions of the mod presented in this page, but all break the "send a message" page.
When the mod is active, clicking on "send a message" displays only the upper part of the page. The layout stops where the modified code is executed.
Is anyone having the same problem?
solmar
PL Nut
 
Posts: 20
Joined: 5:16pm, Thu 26 Jun, 2008

Re: Not working

Postby mikeiam » 11:48am, Fri 05 Sep, 2008

solmar wrote:Is anyone having the same problem?


@solmar

I also tried to implement this mod in my install of 2.10.5 but I end up with the same result you describe.

Can someone post an update to work with 2.10.5?
Thanks.
mikeiam
phpLister
 
Posts: 14
Joined: 8:53pm, Mon 23 Apr, 2007

this mod with pbts_xtra

Postby okker » 9:02am, Mon 03 Nov, 2008

Hello, has anyone succesfully used this mod with pbts_xtra? I got it to work perfectly when I don't use pbts but get the error: The Template could not be loaded. Template ID is "5". in the pbts environment.

Does anyone have the same problem?

Thanx,

Irma
okker
phpLister
 
Posts: 13
Joined: 8:37am, Fri 23 Mar, 2007
Location: Netherlands

lost on this

Postby djc2100 » 3:55am, Wed 04 Mar, 2009

maybe I need to re-read all that, but man - totally over my head. Any Help from anyone would be fantastic.

Thank you all....
djc2100
phpList newbie
 
Posts: 2
Joined: 3:39am, Wed 04 Mar, 2009

Next

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

Who is online

Users browsing this forum: No registered users and 1 guest