Can you update the following PHP script so it will work in v7 as it does on v5?
Notice, not included below is the preceding script in the PHP file where I build the array $our_subs with some of the list ids I want to subscribe this logged in user to based on the products they have paid for in our eCommerce (using VirtueMart). The following checks first to see if the user is already subscribed to lists in array $lists_weekday (with ids 2 thru 8 for weekdays Mon thru Sun) and if so does not subscribe again, and if not will remove, then shows the lists to the user that they are subscribed to (except any that start with ‘OLD’ which are for admin use only).
Also, in my notes where you see 'enrollments' read that as 'products ordered'.
`// UPDATING AcyMailing Subscriptions based on above actual enrollments [products ordered]
/* ENABLE / DISABLE */
// get user's subscription - below when going through the enrolled programs will add/remove
// see scripts here: https://www.acyba.com/acymailing/64-acymailing-developer-documentation.html
// check if AcyMailing is installed
if(!include_once(rtrim(JPATH_ADMINISTRATOR,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_acymailing'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'helper.php')){
//echo 'This code can not work without the AcyMailing Component';
return false;
} else { // begin AcyMailing scripts
// get the lists
//$listClass = acymailing_get('class.list');
//$allLists = $listClass->getLists();
//echo '<br />Lists:<pre>',print_r($allLists,1),'</pre>';
// get the subscriber ID (ID of the AcyMailing user) from his email address or his Joomla user ID
$userClass = acymailing_get('class.subscriber');
$subid = $userClass->subid($user_id);
//echo '<br />Acymailing Subscriber ID: '.$subid;
$subdate = time();
//echo '<br />timestamp: '.$subdate;
// get user's subscriptions
$listsubClass = acymailing_get('class.listsub');
$userSubscriptions = $listsubClass->getSubscription($subid);
//echo '<br />User Subscriptions:<pre>',print_r($userSubscriptions,1),'</pre>';
if (isset($userSubscriptions)) {
foreach ($userSubscriptions as $array) {
$this_listid[] = $array->listid;
}
if (isset($this_listid)) {
if (is_array($this_listid)) {
sort($this_listid);
}
}
}
//echo '<br />User Subscriptions:<pre>',print_r($this_listid,1),'</pre>';
//echo '<br />Weekday Lists:<pre>',print_r($lists_weekday,1),'</pre>';
if (!isset($our_sub)) { // needed so will remove when not in above weekday enrollments
$our_sub=array();
}
if (isset($our_sub)) {
//echo 'subscriptions from above weekday enrollments $our_sub:<pre>',print_r($our_sub,1),'</pre>';
if (is_array($our_sub)) {
sort($our_sub);
}
// get just the User Subscriptions to add
$subscribe = array_diff($our_sub,$this_listid);
//echo '<br />User Subscriptions to add:<pre>',print_r($subscribe,1),'</pre>';
// get just the User Subscriptions to remove
//$remove = array_intersect($this_listid,array_diff($lists_weekday,$this_listid));
$not_lists_weekday = array_diff($lists_weekday,$our_sub);
$remove = array_intersect($not_lists_weekday,$this_listid);
//echo '<br />User Subscriptions to remove:<pre>',print_r($subscribe,1),'</pre>';
/* SETTING AND TESTING ID
subscribe or remove a user from one or several lists
$subscribe = array(2,5,7);//array(28,33); //Id of the lists you want the user to be subscribed to (can be empty)
$remove = array(8); //Id of the lists you want the user to be removed from (can be empty)
//$memberid = $user_id; //ID of the Joomla User or user e-mail (this code supposes that the user is already inserted in AcyMailing!)
/* END SETTING AND TESTING ID */
// $userClass = acymailing_get('class.subscriber');
$newSubscription = array();
if(!empty($subscribe)){
//echo '<br />Subscribe from above weekday enrollments:<pre>',print_r($subscribe,1),'</pre>';
foreach($subscribe as $listId){
$newList = array();
$newList['status'] = 1;
$newSubscription[$listId] = $newList;
// INSERT INTO #__acymailing_listsub
(listid
, subid
, subdate
, unsubdate
, status
) VALUES ('2', '27', NULL, NULL, '1');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$fields = array( // Fields to update
$db->quoteName('listid').' = '.$db->quote($listId),
$db->quoteName('subid').' = '.$db->quote($subid),
$db->quoteName('subdate').' = '.$subdate,
$db->quoteName('unsubdate').' = NULL',
$db->quoteName('status').' = '.$db->quote(1)
);
$query->insert($db->quoteName('#__acymailing_listsub'))->set($fields);
$db->setQuery($query);
$result = $db->query();
}
} // end subscribe
if(!empty($remove)){
//echo '<br />Remove not in above weekday enrollments:<pre>',print_r($remove,1),'</pre>';
foreach($remove as $listId){
$newList = array();
$newList['status'] = 0;
$newSubscription[$listId] = $newList;
}
}
// begin acyba's script that does not work does not instert, keep as it does remove
//if(empty($newSubscription)) return; //there is nothing to do...
//$subid = $userClass->subid($memberid); //this function returns the ID of the user stored in the AcyMailing table from a Joomla User ID or an e-mail address
//if(empty($subid)) return false; //we didn't find the user in the AcyMailing tables
if(!empty($newSubscription)) {
//echo '<br />Subscription Changes:<pre>',print_r($newSubscription,1),'</pre>';
$userClass->saveSubscription($subid,$newSubscription);
}
// end acyba's script that does not work does not instert, keep as it does remove
} else {
//echo '<br />no subscriptions from above enrollments';
}
// get user's subscriptions
$listsubClass = acymailing_get('class.listsub');
$userSubscriptions = $listsubClass->getSubscription($subid);
//echo '<br />New User Subscriptions:<pre>',print_r($userSubscriptions,1),'</pre>';
if (isset($userSubscriptions)) {
foreach ($userSubscriptions as $array) {
$new_listid[] = $array->listid;
}
if (isset($new_listid)) {
if (is_array($new_listid)) {
sort($new_listid);
}
echo '
<a name="subscriptions" id="subscriptions"></a>
<h3 style="margin: 60px auto 20px;"><a href="#subscriptions">Subscriptions</a></h3>
';
//echo '<br />User Subscriptions:<pre>',print_r($new_listid,1),'</pre>';
echo '<p>We use these to send important news and updates to all our students and all those who have asked to be subscribed. If you no longer wish to receive these newsletters you can unsubscribe by clicking the link provided in the emails you receive. Please note that even if you unsubscribe we may still send you important notices when you have students in any of our current programs.</p>
<ul class="our-tight">';
$list_found = 0;
foreach ($new_listid as $array) {
if (stripos($userSubscriptions[$array]->name,'OLD') === false && $userSubscriptions[$array]->status == 1) {
echo '<li>'.$userSubscriptions[$array]->name.'</li>';
$list_found += 1;
}
}
if ($list_found == 0) {
echo '<li>No active subscriptions found</li>';
}
echo '</ul>';
}
}
} // end AcyMailing scripts
unset($our_sub);
unset($this_listid);
unset($newList);
unset($new_listid);
/* end ENABLE / DISABLE */`