[contrib] PHP function to add users / subscribe to lists

3rd party code for phpList

[contrib] PHP function to add users / subscribe to lists

Postby Ravis » 8:42pm, Tue 28 Mar, 2006

I apologize if someone has already done this. I took a quick look around and didn't see anything. I needed it for a project I'm working on, so I wrote my own and figured I'd post it here in case others find it useful. Instructions / details are in the source below. Comments welcome, but as noted I'm pretty busy so I might not have time to provide any kind of support :-)
Code: Select all
<?


/*

phplistSubscribe

Written by Ravis (http://www.ravis.org/)
March 29th, 2006

SUMMARY:
This function provides a simple way to interact with phpList in your own programs (eg: adding a user
who just purchased something from your website to a mailing list).

Takes a list id, an email address, and optionally some attributes and subscribes the user to that list.
If the user already exists, the existing account will be subscribed. If it's a new user they'll be added
first. Users added in this way are pre-confirmed (they will not be sent a confirmation email).

DISCLAIMER:
All the standard rules apply. No responsibility for loss of data, corruption of data, alien abductions,
watching bad movies, unruly children, etc etc. Note that I'm pretty busy and I really don't have time
to support this code, so please don't contact me asking for help implementing it. I release it simply
because I thought it might be useful. I know absolutely nothing about phpList, really, I just installed
it today. The queries here are mostly ripped from the phpList import debug info, the rest of the code is
mine (although I wouldn't be surprised if it matches closely the phpList import code).

REQUIREMENTS:
This function makes use of the PEAR DB abstraction layer, which makes dealing with databases a lot
nicer. If you like there's nothing to stop you from modifying the $db-> commands to standard PHP
mysql functions, but since I use the PEAR DB layer for pretty much everything, I used it here too.
In fact, you could even use the DB layer included with phpList, I didn't because I wanted to keep
the code as independent as possible.

USAGE:
$userId = phplistSubscribe(list,email[,attributes]);

PARAMETERS:
list       - The ID of the list you want to subscribe the user to. No verification is done on this
             field, it's up to you to make sure you pass it a valid ID.
email      - The email address of the user you want to subscribe. This is also how the function tells
             if a user exists or not. If the email doesn't exist in the system it'll be added as a new
             user.
attributes - Optional. An array of NAME=>VALUE pairs. NAME should be a pre-defined attribute in
             phpList. If it doesn't exist, the attribute will be skipped (this function will NOT create
             attributes for you). VALUE is a text field with the value of the attribute. There's a
             special case built in for when NAME==country, the function will do a lookup to determine
             the country ID so that country fields will be normalized. If you specify a country that
             doesn't already exist in phpList, the attribute will be skipped (this function will NOT
             create countries for you). NOTE THAT IF YOU ARE WORKING WITH AN EXISTING USER (a matching
             email address) THEN ANY CONFLICTING ATTRIBUTES WILL BE OVERWRITTEN WITH WHAT YOU SPECIFY
             IN THIS ARRAY!!

RETURN VALUE:
The resulting user id. This will either be the previously existing user matched using the email address
or the new user created with that email address. You can use this value for further processing if you
wish.

EXAMPLE:
<listId>"Test Account","country"=>"Canada");
$userId = phplistSubscribe($listId,$email,$attributes);
print "Added user $userId\n";

?>

TODO:
Turn this function into a PHP class for interacting with phpList programmatically (for someone not me) ;-)

*/




// Include your phpList config.php file here
require("config/config.php");




// Setup and connect to the database (this only needs to be done once per session
// You don't need to change anything here.
include_once("DB.php");
$db = DB::connect("mysql://$database_user:$database_password@$database_host/$database_name");
if (DB::isError($db)) die($db->getMessage());
$db->setFetchMode(DB_FETCHMODE_ASSOC);




// the actual function
function phplistSubscribe($listId,$email,$attributes=NULL) {
  global $db,$table_prefix,$usertable_prefix;

  // if attributes were specified, try and map them to attribute ids in the db
  $attributeIds = array();
  if (is_array($attributes)) {
    foreach ($attributes as $name=>$value) {
      $sql = "SELECT id FROM ".$usertable_prefix."attribute WHERE name='".addslashes($name)."'";
      $id = $db->getOne($sql);
      if ($id) $attributeIds[$name] = $id;
    }
  }
 
  // is there already a user in the system using this email addy?
  $sql = "SELECT id FROM ".$usertable_prefix."user WHERE email='".addslashes($email)."'";
  $userId = $db->getOne($sql);
 
  // if the user doesn't exist, create them
  if (empty($userId)) {
    // create a unique id for the user (and make sure it's unique in the database)
    do {
      $uniqueId = md5(uniqid(mt_rand(0,1000).$email));
      $sql = "SELECT COUNT(*) FROM ".$usertable_prefix."user WHERE uniqid='".addslashes($uniqueId)."'";
      $exists = $db->getOne($sql);
    } while ($exists);
    // insert the user
    $sql = "INSERT INTO ".$usertable_prefix."user (email,entered,confirmed,uniqid) values ('".addslashes($email)."',now(),1,'".addslashes($uniqueId)."')";
    $result = $db->query($sql);
    // get the new user id
    $sql = "SELECT id FROM ".$usertable_prefix."user WHERE uniqid='".addslashes($uniqueId)."'";
    $userId = $db->getOne($sql);
  }
 
  // insert attributes (if any) for the user
  foreach ($attributeIds as $name=>$id) {
    $value = $attributes[$name];
    // special case for countries - get the country id instead of using the name
    if (strtolower($name)=="country") {
      $sql = "SELECT id FROM ".$table_prefix."listattr_countries WHERE name='".addslashes($value)."'";
      $value = $db->getOne($sql);
      // if the country name wasn't found, skip
      if (empty($value)) continue;
    }
    $sql = "REPLACE INTO ".$usertable_prefix."user_attribute (attributeid,userid,value) values ('".addslashes($id)."','".addslashes($userId)."','".addslashes($value)."')";
    $result = $db->query($sql);
  }
 
  // add a note saying we imported them manually
  $sql = "INSERT INTO ".$usertable_prefix."user_history (userid,date,summary) values('".addslashes($userId)."',now(),'Import via phplistSubscribe()')";
  $result = $db->query($sql);
 
  // subscribe them to the specified list
  $sql = "REPLACE INTO ".$table_prefix."listuser (userid,listid,entered) VALUES ('".addslashes($userId)."','".addslashes($listId)."',now())";
  $result = $db->query($sql);
 
  // return the user id
  return($userId);
}


?>
Ravis
phpList newbie
 
Posts: 2
Joined: 8:32pm, Tue 28 Mar, 2006

Postby mouser » 4:53am, Tue 04 Apr, 2006

thanks Ravia!!

this saved me - was able to import 20,000 emails without skipping a beat, wheras built in email import hangs.

in case anyone was interested, here is the php script i used as a front end to let me import a text file of newline separated emails:

Code: Select all
<?php

// phplistadd by mouser@donationcoder.com (www.donationcoder.com), simple front end to
//  phplistSubscribe, written by Ravis (http://www.ravis.org/)
//  which does main work.
// this is infinitely faster than built in phplist import.

// NOTE:
//  your php may not have the pear db functions installed
//  login as root and do: pear lib
//  then: pear install db
//   if its not installed already
//
// NOTE:
// i strongly recomment you add this after the include of config.php in phpSubscribe.php
// unless you like spending hours screaming because php is silently dying or hanging:
// (it's no good to put it here since it will be clear on include of config.php there.
// $error_level = error_reporting(63);


// filename containing newline separated email addresses
$emailfile="emails.txt";
// list id# 2 we want to add users to
$listId=2;


// html display
echo '<html>';
echo 'phplistadd running <br/><br/>';

// include main func
require("phplistSubscribe.php");

//init
$email="";
$attributes=NULL;
$rownum=0;


// open file and loop, processing each line in turn
$fh = fopen($emailfile, 'r');
if ($fh)
   {
   while (!feof($fh))
      {
      $theline = fgets($fh);
      $email = trim($theline);
      ++$rownum;
      if ($email=="")
         continue;
      // add it
      $userId=phplistSubscribe($listId,$email,$attributes);
      // display it
      echo $rownum . ' - ' . $userId . ' - ' . $email . '<br/>' . "\n";
      }
   }
else
   {
   echo 'Failed to open file "' . $emailfile . '".<br/>';
   }


// done
echo 'Processed Lines: ' . $rownum . '<br/>';
echo '</html>';
?>
mouser
phpLister
 
Posts: 8
Joined: 1:03pm, Sat 18 Mar, 2006

How about doing the opposite?

Postby kaon » 5:52am, Tue 04 Apr, 2006

Thanks for the code

I'd like to know how to do the opposite.
What do I have to do to PHPlist's MySQL tables to remove peeps who don't want to receive emails?

Background:
I use PHPLists CSV import, to add customers from my own separate existing table, but a few people want off, and I currently have to do this manually, deleting him from PHPlist thru the admin interface, and also from my own table.
I want to provide a single .php page for them to unsubscribe, this page would change PHPList's tables as well as my table.

Has anyone ever posted such code?
Pseudo-code would be fine too, I just wanna know what changes need to be made to PHPList tables in order to remove a user.

Thanks very much
- DT
kaon
PL Nut
 
Posts: 36
Joined: 7:18am, Fri 23 Dec, 2005

Postby parmendil » 12:22pm, Thu 06 Apr, 2006

Here is a tiny 'unsuscribe' part:
Code: Select all
function phplistUnsubscribe($listId,$email) {
  global $db,$table_prefix,$usertable_prefix;

  // first of all, i must search for the user:
  $sql = "SELECT id FROM ".$usertable_prefix."user WHERE email='".addslashes($email)."'";
  $userId = $db->getOne($sql);

  // then i'll unsuscribe her from the list:
  $sql = "delete from ".$usertable_prefix."listuser where listid = ".$listId." and userid = ".$userId;
  $result = $db->query($sql);

  // add a note saying we unsuscribed them manually
  $sql = "INSERT INTO ".$usertable_prefix."user_history (userid,date,summary) values('".addslashes($userId)."',now(),'Unsuscribed via phplistUnubscribe()')";
  $result = $db->query($sql);

  // return the query's result
  return($result);
}
parmendil
phpLister
 
Posts: 6
Joined: 12:26pm, Wed 29 Mar, 2006
Location: Barcelona, Spain

Postby bevan » 1:50pm, Thu 06 Apr, 2006

Thank you for your contributions. Really appreciated :)

I've added this to the mantis so that it might be inluded in a future release.

I've also moved this thread to the contributions forum.

:)
bevan
PL Master
 
Posts: 465
Joined: 8:07pm, Sun 05 Feb, 2006
Location: Buenos Aires, Argentina

Postby parmendil » 1:57pm, Thu 06 Apr, 2006

Btw, a better approach of the phplistSubscribe and phplistUnsubscribe should use the SendMail() function so the user can receive a mail with the confirmation link.

Something like what is into subscribelib2, but structurated for this specific case:

Code: Select all
(this is part of admin/subscribelib2.php)
(...)
    if (sendMail($email, getConfig("subscribesubject:$id"), $subscribemessage,system_messageheaders($email),$envelope,1)) {
      sendAdminCopy("Lists subscription","\n".$email . " has subscribed\n\n$history_entry");
      addUserHistory($email,$history_subject,$history_entry);
      print $thankyoupage;
(...)
parmendil
phpLister
 
Posts: 6
Joined: 12:26pm, Wed 29 Mar, 2006
Location: Barcelona, Spain

Postby Ravis » 12:53pm, Sat 15 Apr, 2006

Glad people are finding this useful! :-)

Shortly after I built this function I needed something more, so I extended it into a class for working with phpList. The code is below. Again, please note that it works for me, but has not been well tested and is missing a lot of functionality. It still doesn't send confirmation email as parmendil noted, however that could be added by someone (and if someone adds it, it would be nice if they posted the results here so others could make use of it). I'm already handling confirmation via my own code, and didn't want yet another confirmation coming from phpList, so the omission on my part is deliberate. Others have different needs :-)

This code is also not as well commented as the original function. Hopefully everyone can figure it out!

Code: Select all

/*

phplist Class

Written by Ravis (http://www.ravis.org/)
March 29th, 2006

-------------------------------------------------       
SUMMARY:
This class provides a simple way to interact with phpList in your own programs (eg: adding a user
who just purchased something from your website to a mailing list).

-------------------------------------------------       
DISCLAIMER:
All the standard rules apply. No responsibility for loss of data, corruption of data, alien abductions,
watching bad movies, unruly children, etc etc. Note that I'm pretty busy and I really don't have time
to support this code, so please don't contact me asking for help implementing it. I release it simply
because I thought it might be useful. I know absolutely nothing about phpList, really, I just installed
it today. The queries here are mostly ripped from the phpList import debug info, the rest of the code is
mine (although I wouldn't be surprised if it matches closely the phpList import code).

-------------------------------------------------       
REQUIREMENTS:
This function makes use of the PEAR DB abstraction layer, which makes dealing with databases a lot
nicer. If you like there's nothing to stop you from modifying the $db-> commands to standard PHP
mysql functions, but since I use the PEAR DB layer for pretty much everything, I used it here too.
In fact, you could even use the DB layer included with phpList, I didn't because I wanted to keep
the code as independent as possible.

-------------------------------------------------       
FUNCTION REFERENCE:

phpList(path)  --  The class constructor
  Parameters:
    path - optional, the path to your installation of phpList. This allows the class to grab your
           config settings (mainly your database un/pw/etc). If you choose not to specify this value
           the class will assume it's in the phpList directory and look there.
  Returns:
    nothing. constructors don't return :-)

getSubscriberIds(list)
  Parameters:
    list - the phpList mailing list ID
  Returns:
    An array of phpList user IDs currently subscribed to that list

setAttributes(user,attributes[,overwrite])
  Parameters:
    user - the phpList user ID or email address of the user you want to modify attributes for
    attributes - An array of NAME=>VALUE pairs. NAME should be a pre-defined attribute in
                 phpList. If it doesn't exist, the attribute will be skipped (this function will NOT create
                 attributes for you). VALUE is a text field with the value of the attribute. There's a
                 special case built in for when NAME==country, the function will do a lookup to determine
                 the country ID so that country fields will be normalized. If you specify a country that
                 doesn't already exist in phpList, the attribute will be skipped (this function will NOT
                 create countries for you).
    overwrite - a boolean value indicating if you want to overwrite existing attribute values or not.
                defaults to false (values will not be overwritten).
  Returns:
    A boolean value indicating if the update was successful or not

email2id(email)
  Parameters:
    email - the email address you want to find the phpList user ID for
  Returns:
    The phpList user ID that corrosponds to the requested email address, or false if not found

id2email(userId)
  Parameters:
    userId - the phpList user ID you want to get the email address for
  Returns:
    A string containing the email address or false if not found
   
createUser(email[,attributes])
  Parameters:
    email - the email address for the user you're creating
    attributes - optional, attributes for this user (see docs for function setAttributes for details)
  Returns:
    The user ID for the newly created user, or false on failure.

subscribe(user,list)
  Parameters:
    user - the phpList user ID or email address of the user you want to modify attributes for
    list - the phpList mailing list ID
  Returns:
    A boolean indicating success (TRUE) or failure (FALSE)

unsubscribe(user[,list])
  Parameters:
    user - the phpList user ID or email address of the user you want to modify attributes for
    list - optional, the phpList mailing list ID. If no list ID is provided, the user is removed from ALL lists
  Returns:
    A boolean indicating success (TRUE) or failure (FALSE)

-------------------------------------------------       
PARAMETER NOTES:
Most functions accept either an email address or a phpList user ID. If you choose to
provide a phpList user ID, that user must exist. If you provide an email address and
the user doesn't exist, it will be created.

List is the ID of the list you want to subscribe the user to. No verification is done on this
field, it's up to you to make sure you pass it a valid ID.

-------------------------------------------------       
EXAMPLE:

$list = new phpList('/path/to/phplist/install/dir/');
$userId = $list->createUser('test@example.com',array('name'=>'Test User'));
$list->subscribe($userId,123);
$list->setAttributes('test@example.com',array('name'=>'Bob Jones',"country"=>"Canada"));
$members = $list->getSubscriberIds(123);
foreach ($members as $userId) {
  $email = $list->id2email($userId);
  print "$email is subscribed to list 123\n";
}
unset($list);

-------------------------------------------------       
MISSING FUNCTIONALITY:
There's a lot of missing functionality that could be added by interested users. I've created
the functions I needed to perform my tasks, but things like sending confirmations to new users,
adding and removing attributes, etc etc could add a lot of value. If you make changes, please
post them to http://www.phplist.com/forums/viewtopic.php?p=16091 for everyone to share. Thanks!

*/






class phpList {

  var $db;
  var $tablePrefix;
  var $userTablePrefix;



  function phpList($pathToPhpList=NULL) {
    // if no path specified, assume this file is in thephplist dir
    if (empty($pathToPhpList)) $pathToPhpList = dirname(__FILE__);
   
    // Include your phpList config.php file here
    require("$pathToPhpList/config/config.php");
    $this->tablePrefix = $table_prefix;
    $this->userTablePrefix = $usertable_prefix;

    // Setup and connect to the database (this only needs to be done once per session
    // You don't need to change anything here.
    include_once("DB.php");
    $this->db = DB::connect("mysql://$database_user:$database_password@$database_host/$database_name");
    if (DB::isError($this->db)) die($this->db->getMessage());
    $this->db->setFetchMode(DB_FETCHMODE_ASSOC);
  }
 
 
 
  // takes a php mailing list id
  // returns an array of email addresses subscribed to this list
  function getSubscriberIds($listId) {
    $sql = "SELECT userid
              FROM ".$this->tablePrefix."listuser
             WHERE listid='".addslashes($listId)."'";
    $userIds = $this->db->getCol($sql);
    return($userIds);
  }
 
 
 
  function setAttributes($userIdOrEmail,$attributes,$overwrite=false) {
    if (is_numeric($userIdOrEmail)) $userId = $userIdOrEmail;
    else $userId = $this->email2id($userIdOrEmail);
    if (empty($userId)) return(false);
   
    // if attributes were specified, try and map them to attribute ids in the db
    $attributeIds = array();
    if (is_array($attributes)) {
      foreach ($attributes as $name=>$value) {
        $sql = "SELECT id FROM ".$this->userTablePrefix."attribute WHERE name='".addslashes($name)."'";
        $id = $this->db->getOne($sql);
        if ($id) $attributeIds[$name] = $id;
      }
    }
    // insert attributes (if any) for the user
    foreach ($attributeIds as $name=>$id) {
      $value = $attributes[$name];
      // special case for countries - get the country id instead of using the name
      if (strtolower($name)=="country") {
        $sql = "SELECT id FROM ".$this->tablePrefix."listattr_countries WHERE name='".addslashes($value)."'";
        $value = $this->db->getOne($sql);
        // if the country name wasn't found, skip
        if (empty($value)) continue;
      }
      if ($overwrite) $sql = "REPLACE INTO ";
      else $sql = "INSERT IGNORE INTO ";
      $sql .= $this->userTablePrefix."user_attribute (attributeid,userid,value) values ('".addslashes($id)."','".addslashes($userId)."','".addslashes($value)."')";
      $result = $this->db->query($sql);
    }
    return(true);
  }
 
 
 
  function email2id($email) {
    $sql = "SELECT id FROM ".$this->userTablePrefix."user WHERE email='".addslashes($email)."'";
    $userId = $this->db->getOne($sql);
    if (empty($userId)) return(false);
    return($userId);
  }
  function id2email($userId) {
    $sql = "SELECT email FROM ".$this->userTablePrefix."user WHERE id='".addslashes($userId)."'";
    $email = $this->db->getOne($sql);
    if (empty($email)) return(false);
    return($email);
  }
 
 
 
  function createUser($email,$attributes=false) {
    // create a unique id for the user (and make sure it's unique in the database)
    do {
      $uniqueId = md5(uniqid(mt_rand(0,1000).$email));
      $sql = "SELECT COUNT(*) FROM ".$this->userTablePrefix."user WHERE uniqid='".addslashes($uniqueId)."'";
      $exists = $this->db->getOne($sql);
    } while ($exists);

    // insert the user
    $sql = "INSERT INTO ".$this->userTablePrefix."user (email,entered,confirmed,uniqid,htmlemail) values ('".addslashes($email)."',now(),1,'".addslashes($uniqueId)."',1)";
    $result = $this->db->query($sql);

    // add a note saying we imported them manually
    $sql = "INSERT INTO ".$this->userTablePrefix."user_history (userid,date,summary) values('".addslashes($userId)."',now(),'Import via phpList Class')";
    $result = $this->db->query($sql);

    // get the new user id
    $sql = "SELECT id FROM ".$this->userTablePrefix."user WHERE uniqid='".addslashes($uniqueId)."'";
    $userId = $this->db->getOne($sql);
   
    // set attributes if any
    if ($attributes) $this->setAttributes($userId,$attributes);

    return($userId);
  }
 
 
 
  // subscribe a user to a list - accepts either a user id or an email addy
  // user must exist
  function subscribe($userIdOrEmail,$listId) {
    if (is_numeric($userIdOrEmail)) $userId = $userIdOrEmail;
    else $userId = $this->email2id($userIdOrEmail);
    if (empty($userId)) return(false);
   
    // subscribe them to the specified list
    $sql = "INSERT IGNORE INTO ".$this->tablePrefix."listuser (userid,listid,entered) VALUES ('".addslashes($userId)."','".addslashes($listId)."',now())";
    $result = $this->db->query($sql);
   
    // add a note saying we subscribed them manually
    $sql = "INSERT INTO ".$this->userTablePrefix."user_history (userid,date,summary) values('".addslashes($userId)."',now(),'Subscribed to list ".addslashes($listId)." via phpList Class')";
    $result = $this->db->query($sql);

    return(true);
  }



  // unsubscribe an email addy from the list
  // if no list id provided, unsubscribe the user from all lists
  function unsubscribe($userIdOrEmail,$listId=NULL) {
    if (is_numeric($userIdOrEmail)) $userId = $userIdOrEmail;
    else $userId = $this->email2id($userIdOrEmail);
    if (empty($userId)) return(false);

    // unsubscribe them   
    $sql = "DELETE FROM ".$this->tablePrefix."listuser
             WHERE userid='".addslashes($userId)."'";
    if ($listId) $sql .= " AND listid='".addslashes($listId)."'";
    $this->db->query($sql);
   
    // add a note saying we unsubscribed them manually
    $sql = "INSERT INTO ".$this->userTablePrefix."user_history (userid,date,summary) values('".addslashes($userId)."',now(),'Unsubscribed from list ".addslashes($listId)." via phpList Class')";
    $result = $this->db->query($sql);

    return(true);
  }
 
 
 
}


Also, my apologies for delays in responding to this topic. I was expecting the forum to notify me when it was updated and that doesn't seem to have happened (or my antispam has been deleting the notices). I just figured no one found it useful :-)
Ravis
phpList newbie
 
Posts: 2
Joined: 8:32pm, Tue 28 Mar, 2006

Postby jelmer » 6:28pm, Tue 02 May, 2006

Ravis' code works like a charm, so thanks for that.

But I can't get the confirmation message to work so any help would be apreciated...

For initial subscription people enter their details in a Flash interface and Ravis' code is good for that (just made a minor change because I don't want new signups to be confirmed by default).

Following that people need to receive a confirmation e-mail.
After they click the link in their email to confirm I use the standard PHPlist confirmation pages.

But I can't get the confirmation email working. I looked at the code in Subscribelib2.php as parmendil suggested (spent most of the day looking at it actually) but no luck.
Did anyone figure out how to trigger the sending of a confirmation message?

Again, help would be greatly appreciated!

Thanks a lot,
Jelmer
jelmer
phpList newbie
 
Posts: 1
Joined: 2:22pm, Mon 01 May, 2006

Postby flex99 » 9:43pm, Thu 18 May, 2006

Hi,

Try something along the lines of:
Code: Select all
   $spage = '1';
    $subscribemessage = ereg_replace('\[LISTS\]', 'Your List's Name', getUserConfig("subscribemessage:$id",$userId));
   sendMail($email, getConfig("subscribesubject:$spage"), $subscribemessage,system_messageheaders(),$envelope);


You need $listId to be set to appropriate list number. Watch the case in $userId.

Hope this helps.

Flex99 - at - gmail - dot- com

PS> email me if you need help - i don't check this forum often!
flex99
phpList newbie
 
Posts: 1
Joined: 9:34pm, Thu 18 May, 2006

Postby drubarth » 10:00pm, Fri 30 Jun, 2006

I needed to check the subscribe status of a user, so I added the following method to the class:


Code: Select all
  // takes a php mailing list id and e-mail address to determine if currently subscribed
  // returns true if subscribed and false if not
  function getSubscriberStatus($userIdOrEmail, $listId) {

    if (is_numeric($userIdOrEmail)) $userId = $userIdOrEmail;
    else $userId = $this->email2id($userIdOrEmail);
    if (empty($userId)) return(false);

    $sql = "SELECT userid
              FROM ".$this->tablePrefix."listuser
             WHERE listid='".addslashes($listId)."'
          AND userid = '".addslashes($userId)."'";

    $userId = $this->db->getOne($sql);
    if ($this->db->getOne($sql)) return(true);
   else return(false);

  }


Hope it helps.
Darryl Rubarth

Web hosting and support for open-source solutions
www.exyst.com
drubarth
PL Master
 
Posts: 188
Joined: 10:14pm, Fri 17 Dec, 2004

Postby rpverboom » 10:50am, Wed 23 Aug, 2006

Hi, I would love a version that does not use the PEAR DB abstraction layer.
It is another thing to install and maintain.

Does anyone have a version that is a true bold-on to phplist?

Will this function be included in the next version of phplist?

Thanks.

Rob
rpverboom
phpList newbie
 
Posts: 2
Joined: 2:07pm, Thu 10 Aug, 2006

Postby jeangu » 4:19pm, Thu 14 Sep, 2006

A little add to this wonderful phpList class:

Code: Select all
// returns an array of all lists
function getAllLists() {
$sql  = "SELECT id, name ";
$sql .= "FROM ".$this->tablePrefix."list ";
$sql .= "ORDER BY id ";
$arrLists = $this->db->getAll($sql);
return($arrLists);
}

// takes a user email
// returns an array of the lists the user subscribed to
function getListsByEmail($email) {
$sql  = "SELECT l.id ";
$sql .= "FROM ".$this->tablePrefix."listuser lu, ".$this->tablePrefix."list l, ".$this->tablePrefix."user_user uu ";
$sql .= "WHERE uu.email='".addslashes($email)."' ";
$sql .= "AND uu.id=lu.userid ";
$sql .= "AND lu.listid=l.id ";
$listIds = $this->db->getCol($sql);
return($listIds);
}
[/code]
jeangu
phpList newbie
 
Posts: 1
Joined: 4:16pm, Thu 14 Sep, 2006

Postby Colinh » 6:17pm, Sun 29 Oct, 2006

Hi
I am just rewriting the subscribe function shown earlier in this thread without using Pear, using the standard PHP MySQL statements instead.

It appears to me although I may be wrong, that there is a small error in the logic of the code, one of the first things the code does is look up any id's from attribute names, to use the id's later when adding the attributes for the user, but then later on in the code it attempts to do a special case for the country attribute, checking it by attribute name, which the earlier code has already replaced with the id for the attribute, so it will never match.

Have I misunderstood what is happening or is it a buglet.

Colin
Colinh
phpList newbie
 
Posts: 2
Joined: 6:09pm, Sun 29 Oct, 2006

Postby Colinh » 6:56pm, Sun 29 Oct, 2006

Hi
Please ignore my last question, I realised after looking closer that I had misunderstood how it was working, it should work fine, at the moment the REPLACE INTO is not working for me but that is my problem.

Colin
Colinh
phpList newbie
 
Posts: 2
Joined: 6:09pm, Sun 29 Oct, 2006

problem with phpList function

Postby pittstains » 5:54pm, Tue 05 Dec, 2006

Hello,

I am trying to make use of this class, but something is not working somewhere.

It appears everything works up to the include of 'DB.php', although I don't know where/what that file is.

I don't get anything after:
Code: Select all
$this->db = DB::connect("mysql://$database_user:$database_password@$database_host/$database_name");


I don't know what the PEAR DB abstraction layer is. Do I need to be using it for this code to work?

By the way, Colin, you said you were rewriting some of this using standard PHP MySQL statements. Got anything you can post here?

Thanks,
-Pitt
pittstains
PL Nut
 
Posts: 16
Joined: 5:29am, Sat 02 Dec, 2006

Next

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

Who is online

Users browsing this forum: No registered users and 3 guests