diff options
| -rw-r--r-- | BitNewsletter.php | 391 | ||||
| -rw-r--r-- | admin/index.php | 66 | ||||
| -rw-r--r-- | admin/schema_inc.php | 48 | ||||
| -rw-r--r-- | bit_setup_inc.php | 9 | ||||
| -rw-r--r-- | index.php | 12 | ||||
| -rw-r--r-- | lookup_newsletter_inc.php | 13 | ||||
| -rw-r--r-- | templates/admin_newsletters.tpl | 61 |
7 files changed, 468 insertions, 132 deletions
diff --git a/BitNewsletter.php b/BitNewsletter.php new file mode 100644 index 0000000..5d0228d --- /dev/null +++ b/BitNewsletter.php @@ -0,0 +1,391 @@ +<?php +/** + * $Header: /cvsroot/bitweaver/_bit_newsletters/BitNewsletter.php,v 1.1 2005/12/09 18:51:22 spiderr Exp $ + * + * Copyright (c) 2004 bitweaver.org + * All Rights Reserved. See copyright.txt for details and a complete list of authors. + * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details + * + * $Id: BitNewsletter.php,v 1.1 2005/12/09 18:51:22 spiderr Exp $ + * + * Virtual base class (as much as one can have such things in PHP) for all + * derived tikiwiki classes that require database access. + * @package blogs + * + * created 2004/10/20 + * + * @author drewslater <andrew@andrewslater.com>, spiderr <spider@steelsun.com> + * + * @version $Revision: 1.1 $ $Date: 2005/12/09 18:51:22 $ $Author: spiderr $ + */ + +/** + * required setup + */ +require_once( LIBERTY_PKG_PATH.'LibertyContent.php' ); + +define( 'BITNEWSLETTER_CONTENT_TYPE_GUID', 'bitnewsletter' ); +define( 'BITNEWSLETTEREDITION_CONTENT_TYPE_GUID', 'bitnewsletteredition' ); + +class BitNewsletter extends LibertyContent { + function BitNewsletter( $pNlId=NULL, $pContentId=NULL ) { + parent::LibertyContent(); + $this->registerContentType( BITNEWSLETTER_CONTENT_TYPE_GUID, array( + 'content_type_guid' => BITNEWSLETTER_CONTENT_TYPE_GUID, + 'content_description' => 'Newsletter', + 'handler_class' => 'BitNewsletter', + 'handler_package' => 'newsletters', + 'handler_file' => 'BitNewsletter.php', + 'maintainer_url' => 'http://www.bitweaver.org' + ) ); + $this->mNlId = $pNlId; + $this->mContentId = $pContentId; + $this->mContentTypeGuid = BITNEWSLETTER_CONTENT_TYPE_GUID; + } + + function load() { + if( !empty( $this->mNlId ) || !empty( $this->mContentId ) ) { + global $gBitSystem; + + $bindVars = array(); $selectSql = ''; $joinSql = ''; $whereSql = ''; + + $lookupColumn = !empty( $this->mNlId )? 'nl_id' : 'content_id'; + $lookupId = !empty( $this->mNlId )? $this->mNlId : $this->mContentId; + array_push( $bindVars, $lookupId ); + + $this->getServicesSql( 'content_load_function', $selectSql, $joinSql, $whereSql, $bindVars ); + + $query = "SELECT * + FROM `".BIT_DB_PREFIX."tiki_newsletters` tn + INNER JOIN `".BIT_DB_PREFIX."tiki_content` tc ON( tn.`content_id`=tc.`content_id` ) + WHERE `$lookupColumn`=? $whereSql"; + $result = $this->mDb->query($query,$bindVars); + if ($result->numRows()) { + $this->mInfo = $result->fetchRow(); + $this->mNlId = $this->mInfo['nl_id']; + $this->mContentId = $this->mInfo['content_id']; + } + } + return( count( $this->mInfo ) ); + } + + function store( &$pParamHash ) { //$nl_id, $name, $description, $allow_user_sub, $allow_any_sub, $unsub_msg, $validate_addr) { + if( $this->verify( $pParamHash ) ) { + $this->mDb->StartTrans(); + if( parent::store( $pParamHash ) ) { + if( $this->mNlId ) { + $result = $this->mDb->associateUpdate( BIT_DB_PREFIX."tiki_newsletters", $pParamHash['newsletter_store'], array ( "name" => "nl_id", "value" => $this->mNlId ) ); + } else { + $pParamHash['newsletter_store']['content_id'] = $pParamHash['content_id']; + $result = $this->mDb->associateInsert( BIT_DB_PREFIX."tiki_newsletters", $pParamHash['newsletter_store'] ); + } + $this->mDb->CompleteTrans(); + } else { + $this->mDb->RollbackTrans(); + } + } + return( count( $this->mErrors ) == 0 ); + } + + function verify( &$pParamHash ) { + // It is possible a derived class set this to something different + if( empty( $pParamHash['content_type_guid'] ) ) { + $pParamHash['content_type_guid'] = $this->mContentTypeGuid; + } + $pParamHash['newsletter_store']["allow_user_sub"] = (isset($pParamHash["allow_user_sub"]) && $pParamHash["allow_user_sub"] == 'on') ? 'y' : 'n'; + $pParamHash['newsletter_store']["allow_any_sub"] = (isset($pParamHash["allow_any_sub"]) && $pParamHash["allow_any_sub"] == 'on') ? 'y': 'n'; + $pParamHash['newsletter_store']["unsub_msg"] = (isset($pParamHash["unsub_msg"]) && $pParamHash["unsub_msg"] == 'on') ? 'y' : 'n'; + $pParamHash['newsletter_store']["validate_addr"] = (isset($pParamHash["validate_addr"]) && $pParamHash["validate_addr"] == 'on') ? 'y' : 'n'; + return( count( $this->mErrors ) == 0 ); + } + + function get_subscribers($nl_id) { + $query = "select email from `".BIT_DB_PREFIX."tiki_newsletter_subscriptions` where `valid`=? and `nl_id`=?"; + $result = $this->mDb->query($query, array('y',(int)$nl_id)); + $ret = array(); + while ($res = $result->fetchRow()) { + $ret[] = $res["email"]; + } + return $ret; + } + + function remove_newsletter_subscription($nl_id, $email) { + $valid = $this->mDb->getOne("select `valid` from `".BIT_DB_PREFIX."tiki_newsletter_subscriptions` where `nl_id`=? and `email`=?", array((int)$nl_id,$email)); + $query = "delete from `".BIT_DB_PREFIX."tiki_newsletter_subscriptions` where `nl_id`=? and `email`=?"; + $result = $this->mDb->query($query, array((int)$nl_id,$email)); + $this->update_users($nl_id); + } + + function newsletter_subscribe($nl_id, $email) { + global $gBitSmarty; + global $user; + global $sender_email; + $info = $this->get_newsletter($nl_id); + $gBitSmarty->assign('info', $info); + $code = md5( BitUser::genPass() ); + $now = date("U"); + if ($info["validate_addr"] == 'y') { + // Generate a code and store it and send an email with the + // URL to confirm the subscription put valid as 'n' + $foo = parse_url($_SERVER["REQUEST_URI"]); + $foopath = preg_replace('/tiki-admin_newsletter_subscriptions.php/', 'tiki-newsletters.php', $foo["path"]); + $url_subscribe = httpPrefix(). $foopath; + $query = "delete from `".BIT_DB_PREFIX."tiki_newsletter_subscriptions` where `nl_id`=? and `email`=?"; + $result = $this->mDb->query($query,array((int)$nl_id,$email)); + $query = "insert into `".BIT_DB_PREFIX."tiki_newsletter_subscriptions`(`nl_id`,`email`,`code`,`valid`,`subscribed`) values(?,?,?,?,?)"; + $result = $this->mDb->query($query,array((int)$nl_id,$email,$code,'n',(int)$now)); + // Now send an email to the address with the confirmation instructions + $gBitSmarty->assign('mail_date', date("U")); + $gBitSmarty->assign('mail_user', $user); + $gBitSmarty->assign('code', $code); + $gBitSmarty->assign('url_subscribe', $url_subscribe); + $gBitSmarty->assign('server_name', $_SERVER["SERVER_NAME"]); + $mail_data = $gBitSmarty->fetch('bitpackage:newsletters/confirm_newsletter_subscription.tpl'); + @mail($email, tra('Newsletter subscription information at '). $_SERVER["SERVER_NAME"], $mail_data, + "From: $sender_email\r\nContent-type: text/plain;charset=utf-8\r\n"); + } else { + $query = "delete from `".BIT_DB_PREFIX."tiki_newsletter_subscriptions` where `nl_id`=? and `email`=?"; + $result = $this->mDb->query($query,array((int)$nl_id,$email)); + $query = "insert into `".BIT_DB_PREFIX."tiki_newsletter_subscriptions`(`nl_id`,`email`,`code`,`valid`,`subscribed`) values(?,?,?,?,?)"; + $result = $this->mDb->query($query,array((int)$nl_id,$email,$code,'y',(int)$now)); + } + $this->update_users($nl_id); + } + + function confirm_subscription($code) { + global $gBitSmarty; + global $user; + global $sender_email; + $foo = parse_url($_SERVER["REQUEST_URI"]); + $url_subscribe = httpPrefix(). $foo["path"]; + $query = "select * from `".BIT_DB_PREFIX."tiki_newsletter_subscriptions` where `code`=?"; + $result = $this->mDb->query($query,array($code)); + + if (!$result->numRows()) return false; + + $res = $result->fetchRow(); + $info = $this->get_newsletter($res["nl_id"]); + $gBitSmarty->assign('info', $info); + $query = "update `".BIT_DB_PREFIX."tiki_newsletter_subscriptions` set `valid`=? where `code`=?"; + $result = $this->mDb->query($query,array('y',$code)); + // Now send a welcome email + $gBitSmarty->assign('mail_date', date("U")); + $gBitSmarty->assign('mail_user', $user); + $gBitSmarty->assign('code', $res["code"]); + $gBitSmarty->assign('url_subscribe', $url_subscribe); + $mail_data = $gBitSmarty->fetch('bitpackage:newsletters/newsletter_welcome.tpl'); + @mail($res["email"], tra('Welcome to '). $info["name"] . tra(' at '). $_SERVER["SERVER_NAME"], $mail_data, + "From: $sender_email\r\nContent-type: text/plain;charset=utf-8\r\n"); + return $this->get_newsletter($res["nl_id"]); + } + + function unsubscribe($code) { + global $gBitSmarty; + global $user; + global $sender_email; + $foo = parse_url($_SERVER["REQUEST_URI"]); + $url_subscribe = httpPrefix(). $foo["path"]; + $query = "select * from `".BIT_DB_PREFIX."tiki_newsletter_subscriptions` where `code`=?"; + $result = $this->mDb->query($query,array($code)); + + if (!$result->numRows()) return false; + + $res = $result->fetchRow(); + $info = $this->get_newsletter($res["nl_id"]); + $gBitSmarty->assign('info', $info); + $gBitSmarty->assign('code', $res["code"]); + $query = "delete from `".BIT_DB_PREFIX."tiki_newsletter_subscriptions` where `code`=?"; + $result = $this->mDb->query($query,array($code)); + // Now send a bye bye email + $gBitSmarty->assign('mail_date', date("U")); + $gBitSmarty->assign('mail_user', $user); + $gBitSmarty->assign('url_subscribe', $url_subscribe); + $mail_data = $gBitSmarty->fetch('bitpackage:newsletters/newsletter_byebye.tpl'); + @mail($res["email"], tra('Bye bye from '). $info["name"] . tra(' at '). $_SERVER["SERVER_NAME"], $mail_data, + "From: $sender_email\r\nContent-type: text/plain;charset=utf-8\r\n"); + $this->update_users($res["nl_id"]); + return $this->get_newsletter($res["nl_id"]); + } + + function add_all_users($nl_id) { + $query = "select `email` from `".BIT_DB_PREFIX."users_users`"; + $result = $this->mDb->query($query,array()); + while ($res = $result->fetchRow()) { + $email = $res["email"]; + if (!empty($email)) { + $this->newsletter_subscribe($nl_id, $email); + } + } + } + + function update_users($nl_id) { + $users = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."tiki_newsletter_subscriptions` where `nl_id`=?",array((int)$nl_id)); + $query = "update `".BIT_DB_PREFIX."tiki_newsletters` set `users`=? where `nl_id`=?"; + $result = $this->mDb->query($query,array($users,(int)$nl_id)); + } + + function getList( &$pListHash ) { + if ( empty( $pParamHash["sort_mode"] ) ) { + $pListHash['sort_mode'] = 'created_desc'; + } + $this->prepGetList( $pListHash ); + $bindVars = array(); + if( !empty( $pListHash['find'] ) ) { + $findesc = '%' . $pListHash['find'] . '%'; + $mid = " where (`name` like ? or `description` like ?)"; + $bindVars[] = $findesc; + $bindVars[] = $findesc; + } else { + $mid = " "; + } + + $query = "SELECT * + FROM `".BIT_DB_PREFIX."tiki_newsletters` tn INNER JOIN `".BIT_DB_PREFIX."tiki_content` tc ON( tn.`content_id`=tc.`content_id`) + $mid + ORDER BY ".$this->mDb->convert_sortmode( $pListHash['sort_mode'] ); + $result = $this->mDb->query( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'] ); + + $query_cant = "select count(*) from `".BIT_DB_PREFIX."tiki_newsletters` $mid"; + $pListHash['total_records'] = $this->mDb->getOne( $query_cant, $bindVars ); + $pListHash['block_pages'] = 5; + $pListHash['total_pages'] = ceil( $pListHash['total_records'] / $pListHash['max_records'] ); + $pListHash['current_page'] = (!empty( $pListHash['offset'] ) ? floor( $pListHash['offset'] / $pListHash['max_records'] ) + 1 : 1 ); + + $ret = array(); + + while ($res = $result->fetchRow()) { + $res["confirmed"] = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."tiki_newsletter_subscriptions` where `valid`=? and `nl_id`=?",array('y',(int)$res["nl_id"])); + $ret[$res['nl_id']] = $res; + } + + return $ret; + } + + function list_newsletter_subscriptions($nl_id, $offset, $maxRecords, $sort_mode, $find) { + $bindVars = array((int)$nl_id); + if ($find) { + $findesc = '%' . $find . '%'; + $mid = " where `nl_id`=? and (`name` like ? or `description` like ?)"; + $bindVars[] = $findesc; + $bindVars[] = $findesc; + } else { + $mid = " where `nl_id`=? "; + } + + $query = "select * from `".BIT_DB_PREFIX."tiki_newsletter_subscriptions` $mid order by ".$this->mDb->convert_sortmode("$sort_mode"); + $query_cant = "select count(*) from tiki_newsletter_subscriptions $mid"; + $result = $this->mDb->query($query,$bindVars,$maxRecords,$offset); + $cant = $this->mDb->getOne($query_cant,$bindVars); + $ret = array(); + + while ($res = $result->fetchRow()) { + $ret[] = $res; + } + $retval = array(); + $retval["data"] = $ret; + $retval["cant"] = $cant; + return $retval; + } + + function get_unsub_msg($nl_id, $email) { + $foo = parse_url($_SERVER["REQUEST_URI"]); + + $foo = str_replace('send_newsletters', 'newsletters', $foo); + $url_subscribe = httpPrefix(). $foo["path"]; + $code = $this->mDb->getOne("select `code` from `".BIT_DB_PREFIX."tiki_newsletter_subscriptions` where `nl_id`=? and `email`=?",array((int)$nl_id,$email)); + $url_unsub = $url_subscribe . '?unsubscribe=' . $code; + $msg = '<br/><br/>' . tra( 'You can unsubscribe from this newsletter following this link'). ": <a href='$url_unsub'>$url_unsub</a>"; + return $msg; + } + + function remove_newsletter($nl_id) { + $query = "delete from `".BIT_DB_PREFIX."tiki_newsletters` where `nl_id`=?"; + $result = $this->mDb->query($query,array((int)$nl_id)); + $query = "delete from `".BIT_DB_PREFIX."tiki_newsletter_subscriptions` where `nl_id`=?"; + $result = $this->mDb->query($query,array((int)$nl_id)); + $this->remove_object('newsletter', $nl_id); + return true; + } + +} + + + + + + + + + + + + + +class BitNewsletterEdition extends LibertyContent { + function BitNewsletterEdition( $pEditionId, $pContentId=NULL ) { + parent::LibertyContent(); + $this->registerContentType( BITNEWSLETTEREDITION_CONTENT_TYPE_GUID, array( + 'content_type_guid' => BITNEWSLETTEREDITION_CONTENT_TYPE_GUID, + 'content_description' => 'Newsletter', + 'handler_class' => 'BitNewsletter', + 'handler_package' => 'newsletters', + 'handler_file' => 'BitNewsletter.php', + 'maintainer_url' => 'http://www.bitweaver.org' + ) ); + $this->mEditionId = $pEditionId; + $this->mContentId = $pContentId; + $this->mContentTypeGuid = BITNEWSLETTEREDITION_CONTENT_TYPE_GUID; + } + + function replace_edition($nl_id, $subject, $data, $users) { + $now = date("U"); + $query = "insert into `".BIT_DB_PREFIX."tiki_sent_newsletters`(`nl_id`,`subject`,`data`,`sent`,`users`) values(?,?,?,?,?)"; + $result = $this->mDb->query($query,array((int)$nl_id,$subject,$data,(int)$now,$users)); + } + + function get_edition($edition_id) { + $query = "select * from `".BIT_DB_PREFIX."tiki_sent_newsletters` where `edition_id`=?"; + $result = $this->mDb->query($query,array((int)$edition_id)); + if (!$result->numRows()) return false; + $res = $result->fetchRow(); + return $res; + } + + function list_editions($offset, $maxRecords, $sort_mode, $find) { + $bindVars = array(); + if ($find) { + $findesc = '%' . $find . '%'; + $mid = " and (`subject` like ? or `data` like ?)"; + $bindVars[] = $findesc; + $bindVars[] = $findesc; + } else { + $mid = " "; + } + + $query = "select tsn.`edition_id`,tn.`nl_id`,`subject`,`data`,tsn.`users`,`sent`,`name` from `".BIT_DB_PREFIX."tiki_newsletters` tn, `".BIT_DB_PREFIX."tiki_sent_newsletters` tsn "; + $query.= " where tn.`nl_id`=tsn.`nl_id` $mid order by ".$this->mDb->convert_sortmode("$sort_mode"); + $query_cant = "select count(*) from `".BIT_DB_PREFIX."tiki_newsletters` tn, `".BIT_DB_PREFIX."tiki_sent_newsletters` tsn where tn.`nl_id`=tsn.`nl_id` $mid"; + $result = $this->mDb->query($query,$bindVars,$maxRecords,$offset); + $cant = $this->mDb->getOne($query_cant,$bindVars); + $ret = array(); + + while ($res = $result->fetchRow()) { + $ret[] = $res; + } + + $retval = array(); + $retval["data"] = $ret; + $retval["cant"] = $cant; + return $retval; + } + + function remove_edition($edition_id) { + $query = "delete from `".BIT_DB_PREFIX."tiki_sent_newsletters` where `edition_id`=$edition_id"; + $result = $this->mDb->query($query,array((int)$edition_id)); + } + +} + +$BitNewsletter = new BitNewsletter(); + +?> diff --git a/admin/index.php b/admin/index.php index 5a98885..45508fa 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,6 +1,6 @@ <?php -// $Header: /cvsroot/bitweaver/_bit_newsletters/admin/Attic/index.php,v 1.3 2005/12/09 07:07:05 spiderr Exp $ +// $Header: /cvsroot/bitweaver/_bit_newsletters/admin/Attic/index.php,v 1.4 2005/12/09 18:51:22 spiderr Exp $ // Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al. // All Rights Reserved. See copyright.txt for details and a complete list of authors. @@ -14,51 +14,12 @@ $gBitSystem->verifyPermission( 'tiki_p_admin_newsletters' ); require_once( NEWSLETTERS_PKG_PATH.'lookup_newsletter_inc.php' ); -if ($_REQUEST["nl_id"]) { - $info = $nllib->get_newsletter($_REQUEST["nl_id"]); -} else { - $info = array(); - - $info["name"] = ''; - $info["description"] = ''; - $info["allow_user_sub"] = 'y'; - $info["allow_any_sub"] = 'n'; - $info["unsub_msg"] = 'y'; - $info["validate_addr"] = 'y'; -} - -$gBitSmarty->assign('info', $info); - if (isset($_REQUEST["remove"])) { $nllib->remove_newsletter($_REQUEST["remove"]); } if (isset($_REQUEST["save"])) { - if (isset($_REQUEST["allow_user_sub"]) && $_REQUEST["allow_user_sub"] == 'on') { - $_REQUEST["allow_user_sub"] = 'y'; - } else { - $_REQUEST["allow_user_sub"] = 'n'; - } - - if (isset($_REQUEST["allow_any_sub"]) && $_REQUEST["allow_any_sub"] == 'on') { - $_REQUEST["allow_any_sub"] = 'y'; - } else { - $_REQUEST["allow_any_sub"] = 'n'; - } - - if (isset($_REQUEST["unsub_msg"]) && $_REQUEST["unsub_msg"] == 'on') { - $_REQUEST["unsub_msg"] = 'y'; - } else { - $_REQUEST["unsub_msg"] = 'n'; - } - - if (isset($_REQUEST["validate_addr"]) && $_REQUEST["validate_addr"] == 'on') { - $_REQUEST["validate_addr"] = 'y'; - } else { - $_REQUEST["validate_addr"] = 'n'; - } - - $sid = $nllib->replace_newsletter($_REQUEST["nl_id"], $_REQUEST["name"], $_REQUEST["description"], $_REQUEST["allow_user_sub"], $_REQUEST["allow_any_sub"], $_REQUEST["unsub_msg"], $_REQUEST["validate_addr"]); + $sid = $gContent->store( $_REQUEST ); /* $cat_type='newsletter'; $cat_objid = $sid; @@ -78,26 +39,9 @@ if (isset($_REQUEST["save"])) { $gBitSmarty->assign('info', $info); } -$channels = $nllib->getList( $listHash ); - -$cant_pages = ceil( $channels["cant"] / $listHash['max_records'] ); -$gBitSmarty->assign_by_ref('cant_pages', $cant_pages); -$gBitSmarty->assign( 'actual_page', 1 + ( $listHash['offset'] / $listHash['max_records'] ) ); - -if( $channels["cant"] > ( $listHash['offset'] + $listHash['max_records'] ) ) { - $gBitSmarty->assign( 'next_offset', $offset + $listHash['max_records'] ); -} else { - $gBitSmarty->assign('next_offset', -1); -} - -// If offset is > 0 then prev_offset -if( $listHash['offset'] > 0) { - $gBitSmarty->assign('prev_offset', $listHash['offset'] - $listHash['max_records']); -} else { - $gBitSmarty->assign('prev_offset', -1); -} - -$gBitSmarty->assign_by_ref('channels', $channels["data"]); +$newsletters = $gContent->getList( $listHash ); +$gBitSmarty->assign_by_ref( 'newsletters', $newsletters ); +$gBitSmarty->assign_by_ref( 'listInfo', $listHash ); // Fill array with possible number of questions per page /* diff --git a/admin/schema_inc.php b/admin/schema_inc.php index 104076f..25d3f7a 100644 --- a/admin/schema_inc.php +++ b/admin/schema_inc.php @@ -4,9 +4,7 @@ $tables = array( 'tiki_newsletters' => " nl_id I4 AUTO PRIMARY, - name C(200), - description X, - created I8, + content_id I4 NOTNULL, last_sent I8, editions I8, users I8, @@ -15,6 +13,7 @@ $tables = array( unsub_msg C(1) default 'y', validate_addr C(1) default 'y', frequency I8 + CONSTRAINTS ', CONSTRAINT `tiki_nl_ed_con_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."tiki_content`( `content_id` )' ", 'tiki_newsletter_subscriptions' => " @@ -23,26 +22,35 @@ $tables = array( code C(32), valid C(1), subscribed I8, - is_user C(1) NOTNULL default 'n' - CONSTRAINTS ', CONSTRAINT `tiki_nl_sub_nl_id_ref` FOREIGN KEY (`nl_id`) REFERENCES `".BIT_DB_PREFIX."tiki_newsletters`( `nl_id` )' + user_id I4, + group_id I4 NOTNULL PRIMARY + CONSTRAINTS ', CONSTRAINT `tiki_nl_sub_nl_ref` FOREIGN KEY (`nl_id`) REFERENCES `".BIT_DB_PREFIX."tiki_newsletters`( `nl_id` ), + , CONSTRAINT `tiki_nl_group_ref` FOREIGN KEY (`group_id`) REFERENCES `".BIT_DB_PREFIX."users_groups`( `group_id` )' ", -'tiki_sent_newsletters' => " +'tiki_newsletters_editions' => " edition_id I4 AUTO PRIMARY, nl_id I4 NOTNULL, - users I8, - sent I8, - subject C(200), - data X - CONSTRAINTS ', CONSTRAINT `tiki_nl_sent_nl_id_ref` FOREIGN KEY (`nl_id`) REFERENCES `".BIT_DB_PREFIX."tiki_newsletters`( `nl_id` )' + content_id I4 NOTNULL + CONSTRAINTS ', CONSTRAINT `tiki_nl_ed_nl_ref` FOREIGN KEY (`nl_id`) REFERENCES `".BIT_DB_PREFIX."tiki_newsletters`( `nl_id` ) + , CONSTRAINT `tiki_nl_ed_con_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."tiki_content`( `content_id` )' +", + +'tiki_newsletters_mailings' => " + edition_id I4 NOTNULL, + queue_date I8, + send_date I8, + emails_sent I8 + CONSTRAINTS ', CONSTRAINT `tiki_nl_mail_ed_ref` FOREIGN KEY (`edition_id`) REFERENCES `".BIT_DB_PREFIX."tiki_newsletters_editions`( `edition_id` )' ", -'tiki_newsletter_groups_map' => " - nl_id I4 NOTNULL PRIMARY, - group_id I4 NOTNULL PRIMARY, - code C(32) - CONSTRAINTS ', CONSTRAINT `tiki_nl_groups_nl_id_ref` FOREIGN KEY (`nl_id`) REFERENCES `".BIT_DB_PREFIX."tiki_newsletters`( `nl_id` ), - , CONSTRAINT `tiki_nl_groups_id_ref` FOREIGN KEY (`group_id`) REFERENCES `".BIT_DB_PREFIX."users_groups`( `group_id` )' +'tiki_newsletters_mailings_queue' => " + edition_id I4 PRIMARY, + email C(160) PRIMARY, + user_id C(1), + sent_date I8 + CONSTRAINTS ', CONSTRAINT `tiki_nl_mailq_ed_ref` FOREIGN KEY (`edition_id`) REFERENCES `".BIT_DB_PREFIX."tiki_newsletters_editions`( `edition_id` ), + , CONSTRAINT `tiki_nl_mailq_user_ref` FOREIGN KEY (`users_id`) REFERENCES `".BIT_DB_PREFIX."users_users`( `users_id` )' " ); @@ -64,10 +72,12 @@ $gBitInstaller->registerPackageInfo( NEWSLETTERS_PKG_NAME, array( // ### Indexes $indices = array ( 'tiki_nl_sub_nl_idx' => array( 'table' => 'tiki_newsletter_subscriptions', 'cols' => 'nl_id', 'opts' => NULL ), + 'tiki_nl_sub_group_idx' => array( 'table' => 'tiki_newsletter_subscriptions', 'cols' => 'group_id', 'opts' => NULL ), 'tiki_nl_sub_email_idx' => array( 'table' => 'tiki_newsletter_subscriptions', 'cols' => 'email', 'opts' => NULL ), - 'tiki_nl_sent_nl_idx' => array( 'table' => 'tiki_sent_newsletters', 'cols' => 'nl_id', 'opts' => NULL ), - 'tiki_nl_group_idx' => array( 'table' => 'tiki_newsletter_groups', 'cols' => 'group_id', 'opts' => NULL ), + 'tiki_nl_ed_nl_idx' => array( 'table' => 'tiki_newsletters_editions', 'cols' => 'nl_id', 'opts' => NULL ), 'tiki_nl_group_nl_idx' => array( 'table' => 'tiki_newsletter_groups', 'cols' => 'nl_id', 'opts' => NULL ), + 'tiki_nl_mq_email_idx' => array( 'table' => 'tiki_newsletters_mailings_queue', 'cols' => 'email', 'opts' => NULL ), + 'tiki_nl_mq_sent_idx' => array( 'table' => 'tiki_newsletters_mailings_queue', 'cols' => 'sent_date', 'opts' => NULL ), ); $gBitInstaller->registerSchemaIndexes( LIBERTY_PKG_NAME, $indices ); diff --git a/bit_setup_inc.php b/bit_setup_inc.php new file mode 100644 index 0000000..95a074d --- /dev/null +++ b/bit_setup_inc.php @@ -0,0 +1,9 @@ +<?php +global $gBitSystem; + +$gBitSystem->registerPackage( 'Newsletters', dirname( __FILE__ ).'/' ); + +if( $gBitSystem->isPackageActive( NEWSLETTERS_PKG_NAME ) ) { + $gBitSystem->registerAppMenu( NEWSLETTERS_PKG_DIR, NEWSLETTERS_PKG_NAME, NEWSLETTERS_PKG_URL.'index.php', 'bitpackage:newsletters/menu_newsletters.tpl', true ); +} +?> @@ -1,6 +1,6 @@ <?php -// $Header: /cvsroot/bitweaver/_bit_newsletters/index.php,v 1.3 2005/12/09 15:55:45 squareing Exp $ +// $Header: /cvsroot/bitweaver/_bit_newsletters/index.php,v 1.4 2005/12/09 18:51:22 spiderr Exp $ // Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al. // All Rights Reserved. See copyright.txt for details and a complete list of authors. @@ -47,7 +47,7 @@ $gBitSmarty->assign('email', $user_email); if( isset( $_REQUEST["subscribe"] ) ) { $gBitSystem->verifyPermission( 'bit_p_subscribe_newsletters' ); $feedback['success'] = tra( "Thanks for your subscription. You will receive an email soon to confirm your subscription. No newsletters will be sent to you until the subscription is confirmed." ); - + if( !$gBitUser->hasPermission( 'tiki_p_subscribe_email' ) ) { $_REQUEST["email"] = $gBitUser->mInfo['email']; } @@ -56,15 +56,9 @@ if( isset( $_REQUEST["subscribe"] ) ) { $nllib->newsletter_subscribe( $_REQUEST["nl_id"], $_REQUEST["email"] ); } -if( isset( $_REQUEST["info"] ) ) { - $nl_info = $nllib->get_newsletter($_REQUEST["nl_id"]); - - $gBitSmarty->assign( 'nl_info', $nl_info ); - $gBitSmarty->assign( 'subscribe', 'y' ); -} /* List newsletters */ $listHash = array(); -$channels = $nllib->getList( $listHash ); +$channels = $gContent->getList( $listHash ); for ($i = 0; $i < count($channels["data"]); $i++) { /* diff --git a/lookup_newsletter_inc.php b/lookup_newsletter_inc.php index cdb3d19..996f744 100644 --- a/lookup_newsletter_inc.php +++ b/lookup_newsletter_inc.php @@ -1,13 +1,16 @@ <?php +require_once( NEWSLETTERS_PKG_PATH.'BitNewsletter.php' ); -if (!isset($_REQUEST["nl_id"])) { - $_REQUEST["nl_id"] = 0; +if( empty( $gContent ) || !is_object( $gContent ) || !$gContent->isValid() ) { + $nlId = !empty( $_REQUEST['nl_id'] ) ? $_REQUEST['nl_id'] : NULL; + $conId = !empty( $_REQUEST['content_id'] ) ? $_REQUEST['content_id'] : NULL; + $gContent = new BitNewsletter( $nlId, $conId ); + $gContent->load(); + $gBitSmarty->assign_by_ref( 'gContent', $gContent ); } -$gBitSmarty->assign('nl_id', $_REQUEST["nl_id"]); - - $gBitSmarty->assign('individual', 'n'); +// $gBitSmarty->assign('individual', 'n'); /* if ($userlib->object_has_one_permission($_REQUEST["nl_id"], 'newsletter')) { $gBitSmarty->assign('individual', 'y'); diff --git a/templates/admin_newsletters.tpl b/templates/admin_newsletters.tpl index 2eb51c3..fdc49e4 100644 --- a/templates/admin_newsletters.tpl +++ b/templates/admin_newsletters.tpl @@ -1,5 +1,5 @@ <a class="pagetitle" href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/index.php">{tr}Admin newsletters{/tr}</a> - + {if $gBitSystemPrefs.feature_help eq 'y'} <a href="http://bitweaver.org/wiki/PackageNewsletters" target="help" title="{tr}Tikiwiki.org help{/tr}: {tr}Newsletters{/tr}"><img class="icon" src="{$smarty.const.IMG_PKG_URL}icons/help.gif" alt="help" /></a> {/if} @@ -15,22 +15,22 @@ <h2>{tr}Create/edit newsletters{/tr}</h2> {if $individual eq 'y'} -<a href="{$smarty.const.KERNEL_PKG_URL}object_permissions.php?objectName=newsletter%20{$info.name}&object_type=newsletter&permType=newsletters&object_id={$info.nl_id}">{tr}There are individual permissions set for this newsletter{/tr}</a><br /><br /> +<a href="{$smarty.const.KERNEL_PKG_URL}object_permissions.php?objectName=newsletter%20{$gContent->mInfo.name}&object_type=newsletter&permType=newsletters&object_id={$gContent->mInfo.nl_id}">{tr}There are individual permissions set for this newsletter{/tr}</a><br /><br /> {/if} <form action="{$smarty.const.NEWSLETTERS_PKG_URL}admin/index.php" method="post"> -<input type="hidden" name="nl_id" value="{$info.nl_id|escape}" /> +<input type="hidden" name="nl_id" value="{$gContent->mInfo.nl_id|escape}" /> <table class="panel"> -<tr><td>{tr}Name{/tr}:</td><td><input type="text" name="name" value="{$info.name|escape}" /></td></tr> -<tr><td>{tr}Description{/tr}:</td><td><textarea name="description" rows="4" cols="40">{$info.description|escape}</textarea></td></tr> +<tr><td>{tr}Name{/tr}:</td><td><input type="text" name="title" value="{$gContent->mInfo.title|escape}" /></td></tr> +<tr><td>{tr}Description{/tr}:</td><td><textarea name="edit" rows="4" cols="40">{$gContent->mInfo.data|escape:html}</textarea></td></tr> <tr><td>{tr}Users can subscribe/unsubscribe to this list{/tr}</td><td> -<input type="checkbox" name="allow_user_sub" {if $info.allow_user_sub eq 'y'}checked="checked"{/if} /></td></tr> +<input type="checkbox" name="allow_user_sub" {if $gContent->mInfo.allow_user_sub eq 'y'}checked="checked"{/if} /></td></tr> <tr><td>{tr}Users can subscribe any email address{/tr}</td><td> -<input type="checkbox" name="allow_any_sub" {if $info.allow_any_sub eq 'y'}checked="checked"{/if} /></td></tr> +<input type="checkbox" name="allow_any_sub" {if $gContent->mInfo.allow_any_sub eq 'y'}checked="checked"{/if} /></td></tr> <tr><td>{tr}Add unsubscribe instructions to each newsletter{/tr}</td><td> -<input type="checkbox" name="unsub_msg" {if $info.unsub_msg eq 'y'}checked="checked"{/if} /></td></tr> +<input type="checkbox" name="unsub_msg" {if $gContent->mInfo.unsub_msg eq 'y'}checked="checked"{/if} /></td></tr> <tr><td>{tr}Validate email addresses{/tr}</td><td> -<input type="checkbox" name="validate_addr" {if $info.validate_addr eq 'y'}checked="checked"{/if} /></td></tr> +<input type="checkbox" name="validate_addr" {if $gContent->mInfo.validate_addr eq 'y'}checked="checked"{/if} /></td></tr> <tr class="panelsubmitrow"><td colspan="2"><input type="submit" name="save" value="{tr}Save{/tr}" /></td></tr> </table> </form> @@ -48,6 +48,7 @@ </tr> </table> + <table class="panel"> <tr> <th><a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/index.php?offset={$offset}&sort_mode={if $sort_mode eq 'nl_id_desc'}nl_id_asc{else}nl_id_desc{/if}">{tr}ID{/tr}</a></th> @@ -59,38 +60,22 @@ <th>{tr}action{/tr}</th> </tr> {cycle values="even,odd" print=false} -{section name=user loop=$channels} +{foreach key=nlId from=$newsletters item=nl} <tr class="{cycle}"> -<td>{$channels[user].nl_id}</td> -<td>{$channels[user].name}</td> -<td>{$channels[user].description}</td> -<td>{$channels[user].users} ({$channels[user].confirmed})</td> -<td>{$channels[user].editions}</td> -<td>{$channels[user].last_sent|bit_short_datetime}</td> +<td>{$nlIid}</td> +<td>{$nl.title}</td> +<td>{$nl.data}</td> +<td>{$nl.users} ({$channels[user].confirmed})</td> +<td>{$nl.editions}</td> +<td>{$nl.last_sent|bit_short_datetime}</td> <td> - <a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/index.php?offset={$offset}&sort_mode={$sort_mode}&remove={$channels[user].nl_id}">{tr}remove{/tr}</a> - <a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/index.php?offset={$offset}&sort_mode={$sort_mode}&nl_id={$channels[user].nl_id}">{tr}edit{/tr}</a> - <a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/admin_newsletter_subscriptions.php?nl_id={$channels[user].nl_id}">{tr}subscriptions{/tr}</a> - {if $channels[user].individual eq 'y'}({/if}<a href="{$smarty.const.KERNEL_PKG_URL}object_permissions.php?objectName=newsletter%20{$channels[user].name}&object_type=newsletter&permType=newsletters&object_id={$channels[user].nl_id}">{tr}perms{/tr}</a>{if $channels[user].individual eq 'y'}){/if} + <a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/index.php?offset={$offset}&sort_mode={$sort_mode}&remove={$nlId}">{tr}remove{/tr}</a> + <a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/index.php?offset={$offset}&sort_mode={$sort_mode}&nl_id={$nlId}">{tr}edit{/tr}</a> + <a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/admin_newsletter_subscriptions.php?nl_id={$nlId}">{tr}subscriptions{/tr}</a> + {if $channels[user].individual eq 'y'}({/if}<a href="{$smarty.const.KERNEL_PKG_URL}object_permissions.php?objectName=newsletter%20{$nl.title}&object_type={$smarty.const.BITNEWSLETTER_CONTENT_TYPE_GUID}&permType=newsletters&object_id={$nlId}">{tr}perms{/tr}</a>{if $nl.individual eq 'y'}){/if} </td> </tr> -{/section} +{/foreach} </table> -<div class="pagination"> -{if $prev_offset >= 0} -[<a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/index.php?find={$find}&offset={$prev_offset}&sort_mode={$sort_mode}">{tr}prev{/tr}</a>] -{/if} -{tr}Page{/tr}: {$actual_page}/{$cant_pages} -{if $next_offset >= 0} - [<a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/index.php?find={$find}&offset={$next_offset}&sort_mode={$sort_mode}">{tr}next{/tr}</a>] -{/if} -{if $direct_pagination eq 'y'} -<br /> -{section loop=$cant_pages name=foo} -{assign var=selector_offset value=$smarty.section.foo.index|times:$maxRecords} -<a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/index.php?find={$find}&offset={$selector_offset}&sort_mode={$sort_mode}"> -{$smarty.section.foo.index_next}</a> -{/section} -{/if} -</div> +{pagination} |
