Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Addon Module Sample File
- *
- * This example addon module demonstrates all the functions an addon module can contain.
- * Please refer to the full documentation @ http://docs.whmcs.com/Addon_Modules for more details.
- *
- * @package WHMCS
- * @author WHMCS Limited <development@whmcs.com>
- * @copyright Copyright (c) WHMCS Limited 2005-2013
- * @license http://www.whmcs.com/license/ WHMCS Eula
- * @version $Id$
- * @link http://www.whmcs.com/
- */
- if (!defined("WHMCS"))
- die("This file cannot be accessed directly");
- function sendtomailchimp_config() {
- $configarray = array(
- "name" => "Send to MailChimp",
- "description" => "This is an open source addon module to send registred customers to a MailChimp List",
- "version" => "1.1",
- "author" => "Elson Sartori",
- "language" => "english",
- "fields" => array(
- // "option1" => array ("FriendlyName" => "Option1", "Type" => "text", "Size" => "25", "Description" => "Textbox", "Default" => "Example", ),
- // "option2" => array ("FriendlyName" => "Option2", "Type" => "password", "Size" => "25", "Description" => "Password", ),
- // "option3" => array ("FriendlyName" => "Option3", "Type" => "yesno", "Size" => "25", "Description" => "Sample Check Box", ),
- // "option4" => array ("FriendlyName" => "Option4", "Type" => "dropdown", "Options" => "1,2,3,4,5", "Description" => "Sample Dropdown", "Default" => "3", ),
- // "option5" => array ("FriendlyName" => "Option5", "Type" => "radio", "Options" => "Demo1,Demo2,Demo3", "Description" => "Radio Options Demo", ),
- // "option6" => array ("FriendlyName" => "Option6", "Type" => "textarea", "Rows" => "3", "Cols" => "50", "Description" => "Description goes here", "Default" => "Test", ),
- "apikey1" => array ("FriendlyName" => "Api Key", "Type" => "text", "Size" => "50", "Description" => "Your API key retrieved from https://admin.mailchimp.com/account/api/", "Default" => "", ),
- "listid1" => array ("FriendlyName" => "List ID", "Type" => "text", "Size" => "10", "Description" => "Your list Unique ID obtained by going to http://admin.mailchimp.com/lists/ and clicking on the Settings link for the list. Unique ID found a the bottom of the page.", "Default" => "", ),
- "dc1" => array ("FriendlyName" => "DataCenter", "Type" => "text", "Size" => "4", "Description" => "Your datacenter. Retrieved from dashboard URL eg. - https://us1.admin.mailchimp.com/", "Default" => "us1", ),
- "groupname1" => array("FriendlyName" => "Group Name", "Type" => "text", "Size" => "20", "Description" => "Name of Group field on MailChimp. You need to create this text field by going to http://admin.mailchimp.com/lists/ and clicking on the Settings link for the list.", "Default" => "group", ),
- // "dbloptin1" => array ("FriendlyName" => "Double OptIn", "Type" => "yesno", "Size" => "5", "Description" => "Set this if you would like the user to confirm their subscription before being added to your list", "Default" => "", ),
- "groupid1" => array ("FriendlyName" => "Group ID", "Type" => "text", "Size" => "10", "Description" => "Clients Group ID to send to MailChimp. 0 = Users without group", "Default" => "0",),
- ));
- return $configarray;
- }
- function sendtomailchimp_output($vars) {
- $modulelink = $vars['modulelink'];
- $version = $vars['version'];
- $api_key = $vars['apikey1'];
- $list_id = $vars['listid1'];
- $datacenter = $vars['dc1'];
- // $doubleoptin1 = $vars['dbloptin1'];
- $group1 = $vars['groupid1'];
- //$groupid = strval($vars['groupid1']);
- $groupid = $_POST['groupid1'];
- $emailtype = "html";
- $doubleoptin = "false";
- $output = "php";
- $groupname = $vars['groupname1'];
- $LANG = $vars['_lang'];
- $table0 = "tblclientgroups";
- $fields0 = "id,groupname";
- $where0 = array('id' => $groupid);
- $table1 = "tblclients";
- $fields1 = "id,firstname,lastname,email,emailoptout,groupid,status";
- // $where = array('email' => $vars['email']);
- //$where = array('email' => $vars['email']);
- //$where1 = array('id' => $vars['id']);
- $where1 = array('groupid' => $groupid);
- echo '<p>'.$LANG['intro'].'</p>
- <p>'.$LANG['description'].'</p>
- <p>'.$LANG['documentation'].'</p>';
- echo '<p></p>';
- // GET List
- if(empty($_GET['action'])) {
- //Bloco 1 sem função ainda
- if ($_GET['outracoisa'] == 'successo1') {
- echo '<div class="infobox">'.$LANG['sucesso1'].'</div>';
- } elseif ($_GET['outracoisa'] == 'successo2') {
- echo '<div class="infobox">'.$LANG['successo2'].'</div>';
- } elseif ($_GET['outracoisa'] == 'falha1') {
- echo '<div class="errorbox">'.$LANG['falha1'].'</div>';
- } //Fim Bloco 1
- echo "<h2>";
- echo $LANG['title1'];
- echo "</h2>\r\n<h3>";
- echo $LANG['description1'];
- echo "</h3>\r\n";
- echo "<form action=\"".$modulelink."&action=sendnow\" method=\"post\" name=\"send_now_form\" enctype=\"multipart/form-data\" style=\"margin-bottom:60px;\">\r\n";
- echo "<p><b>";
- /// echo $LANG['groupid']."</b>";
- /// echo "<span style=\"color:red\">".$LANG['groupid']."</span>";
- echo "<span style=\"color:red\">Group ID</span></b></p>";
- echo "</br>\r\n<input type=\"text\" name=\"groupid1\" style=\"width:20px\" /></p>\r\n";
- echo "<p><input type=\"submit\" value=\"";
- /// echo $LANG['sendbutton'];
- echo "Enviar";
- echo "\" /></p>\r\n";
- // echo "<p><input type=\"button\" value=\"";
- // echo $LANG['button01'];
- // echo "\" /></p>\r\n";
- echo "</form>\r\n";
- // if (!$varteste) {
- // include(ROOTDIR . "/modules/addons/sendtomailchimp/other/anotherfile.php");
- // }
- }
- // SEND
- if($_GET['action'] == 'sendnow') {
- echo '<p>*** Processing ***</p>';
- echo '<p><b>Groupname: </b>';
- var_dump($groupname);
- echo '</p>';
- //$groupid = $_POST['groupid1'];
- echo '<p><b>groupid: </b>';
- var_dump('$groupid');
- echo '</p>';
- //echo '<p><b>Where: </b>'.$where1[id].'</p>';
- echo '<p><b>Where0: </b>';
- var_dump($where0);
- echo '</p>';
- echo '<p><b>Where1: </b>';
- var_dump($where1);
- echo '</p>';
- $groups = select_query($table0,$fields0,$where0);
- echo '<p><b>Groups: </b>';
- var_dump($groups);
- echo '</p>';
- if ($groups){
- $row0 = mysql_fetch_assoc($groups);
- echo '<p><b>Row0(dump): </b>';
- var_dump($row0);
- echo '</p>';
- //$usergroup = $row0[groupname];
- $usergroup = str_replace(" ", "%20", $row0['groupname']);
- echo '<p><b>usergroup(dump): </b>';
- var_dump($usergroup);
- echo '</p>';
- }
- $clients = select_query($table1,$fields1,$where1);
- //$group1 = $clients
- if($clients){
- $groupname = strtoupper($groupname);
- echo '<p><b>groupname: </b>';
- var_dump($groupname);
- echo '</p>';
- echo '<p>.</p>';
- while($row = mysql_fetch_assoc($clients)){
- ///echo '<p><b>Row: </b>'.$row[id].' | '.$row[firstname].' | '.$row[lastname].' | '.$row[email].' | '.$row[groupid].' | '.$row[emailoptout].' -</p>';
- echo '<p><b>Row: </b>';
- var_dump($row);
- echo '</p>';
- // update_query('tbltickets', array('userid' => $vars['userid'], 'email' => '', 'name' => ''), array('id' => $ticket['id']));
- //$id1 = $row[id];
- $first_name = str_replace(" ", "%20", $row['firstname']);
- $last_name = str_replace(" ", "%20", $row['lastname']);
- $email = $row['email'];
- $doubleoptin = $row['emailoptout'];
- //echo '<p><b>group1 (before): </b>';
- //var_dump($group1);
- //echo '</p>';
- $group1 = $row[groupid];
- //echo '<p><b>group1 (after row): </b>';
- //var_dump($group1);
- //echo '</p>';
- ////$group1 = strval($group1);
- //echo '<p><b>group1 (after str): </b>';
- //var_dump($group1);
- //echo '</p>';
- //$url = "http://$datacenter.api.mailchimp.com/1.3/?output=$output&method=listSubscribe&apikey=$api_key&id=$list_id&email_address=$email&merge_vars[FNAME]=$first_name&merge_vars[LNAME]=$last_name&email_type=$emailtype&double_optin=$doubleoptin&merge_vars[$groupname]=$group1";
- $url = "http://$datacenter.api.mailchimp.com/1.3/?output=$output&method=listSubscribe&apikey=$api_key&id=$list_id&email_address=$email&merge_vars[FNAME]=$first_name&merge_vars[LNAME]=$last_name&email_type=$emailtype&double_optin=$doubleoptin&merge_vars[$groupname]=$usergroup";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $retval = curl_exec($ch);
- curl_close($ch);
- echo '<p>..</p>';
- logModuleCall('SendToMailChimp','send',$url,$retval,'','');
- //logModuleCall($module,$action,$requeststring,$responsedata,$processeddata,$replacevars);
- //logActivity("Debug: SendToMailChimp - URL: $url - Response: ".htmlentities($retval));
- }//while
- }//if
- echo '<p>'.$clients[id].'</p>';
- echo '<p>...</p>';
- if(!$clients){
- echo '<p>...</p>
- <p>.:|Attention|:.</p>
- <p>*** Module Error! ***</p>
- <p>...</p>';
- }
- echo '<p>***</p>
- <p>Execution Ended!!!</p>
- <p>***</p>';
- }
- if ($successful) {
- $result = "Success...";
- } else {
- $result = "Error...";
- }
- return $result;
- }
- function sendtomailchimp_sidebar($vars) {
- $modulelink = $vars['modulelink'];
- $version = $vars['version'];
- $LANG = $vars['_lang'];
- $sidebar = '<span class="header"><img src="images/icons/addonmodules.png" class="absmiddle" width="16" height="16" />'.$LANG['addonname'].'</span>
- <ul class="menu">
- <li><a href="'.$modulelink.'">'.$LANG['sidebarmain'].'</a></li>
- <li><a>'.$LANG['sidebarversion'].' '.$version.'</a></li>
- </ul>';
- return $sidebar;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement