21
trabis
Re: Notifications based on criteria
  • 2008/12/20 13:16

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Another thing you should take care is in the registration form is to provide selections boxes populated with the languages available on ads module instead of a simple text field.

This would avoid that eventual typos would get in the way of this notification filter. Users may not know that they have to enter exactly what is shown in the ads module.

22
deka87
Re: Notifications based on criteria
  • 2008/12/20 15:10

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


that's what i found in the adsmod.php

le="color: #000000"><?php // Notification $notification_handler =& xoops_gethandler('notification'); $tags = array(); $tags['ADS_TITLE'] = $ads->getVar('ads_title'); $tags['ADS_LANG'] = $ads->getVar('ads_lang1').' to '.$ads->getVar('ads_lang2'); $tags['ADS_DESC'] = $ads->getVar('ads_desc'); $tags['ADS_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/adsitem.php?ads_id=' . $ads_id; $notification_handler->triggerEvent('global', 0, 'new_ads', $tags); $notification_handler->triggerEvent('category', $cat_id, 'new_ads', $tags); $notification_handler->triggerEvent('ads', $ads_id, 'approve', $tags); } else { $messagesent = _AM_CATADS_ERROR_UPDATE; } redirect_header("index.php?op=show&sel_status=2", 1, $messagesent); exit(); }


I guess this is what we need.

As in regard to the the selections boxes, I thought it might be a good idea, but i have over 700 registered users and it'd be pretty tough to make them choose it again, there are over 100 languages in my database so I will need to make a dropdown to choose from. But dropdowns are not searchable in my profile/search.php which is needed for another section of my website.

So I gave it a shot and edited adsmod.php like this:

le="color: #000000"><?php // Notification $notification_handler =& xoops_gethandler('notification'); $tags = array(); $tags['ADS_TITLE'] = $ads->getVar('ads_title'); $tags['ADS_LANG'] = $ads->getVar('ads_lang1').' to '.$ads->getVar('ads_lang2'); $tags['ADS_DESC'] = $ads->getVar('ads_desc'); $tags['ADS_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/adsitem.php?ads_id=' . $ads_id; $sql = ' SELECT * FROM '.$this->db->prefix('xoopsnotifications').' LEFT JOIN '.$this->db->prefix('user_profile').' ON not_uid = profileid WHERE not_modid = '.$mod_id.' AND not_itemid = '.0.' AND not_category = '."'global'".' AND not_event = '."'new_ads'".' AND ((source_language <> '.$ads->getVar('ads_lang1').') OR (target_language <> '.$ads->getVar('ads_lang2').'))'; $result = $xoopsDB->query($sql); $user_list = array(); while($row = $xoopsDB->fetchArray($result)){ $user_list[] = $row['not_uid']; } $notification_handler->triggerEvent('global', 0, 'new_ads', $tags, $user_list); $notification_handler->triggerEvent('category', $cat_id, 'new_ads', $tags); $notification_handler->triggerEvent('ads', $ads_id, 'approve', $tags); } else { $messagesent = _AM_CATADS_ERROR_UPDATE; } redirect_header("index.php?op=show&sel_status=2", 1, $messagesent); exit(); }


but got a blank page again
Mind anchors

23
ghia
Re: Notifications based on criteria
  • 2008/12/21 2:03

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


And with the steps?

24
deka87
Re: Notifications based on criteria
  • 2008/12/21 10:33

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


OK, my report starting from the 4th step:

4. Notification is received
5. Done
6. Notification is still received.
7. Done
8. Unable to reach adsmode.php only get a blank page.

So whenever I add sql I get a blank page =(
Mind anchors

25
ghia
Re: Notifications based on criteria
  • 2008/12/21 10:54

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Means we have two problems:
- the code for the database request is not working (step 8)
- the user list doesn't seem to deselect the users in it (step 6).
First we need to resolve the problem from step 6.
Can you see what queries are used in debug for table xoopsnotifications?
Look also the queries up when enabling or disabling this notification.

26
deka87
Re: Notifications based on criteria
  • 2008/12/21 11:07

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


these are queries i got in debug when enabling global notifications in catads for admin (uid =1 ofc):

le="color: #000000"><?php SELECT * FROM U39uxs_config WHERE (conf_modid = '1' AND conf_catid = '1') ORDER BY conf_order ASC SELECT sess_data FROM U39uxs_session WHERE sess_id = '77656ccbf6d1a2961f21accf8e7c7614' ( 0.023843) SELECT * FROM U39uxs_users u, U39uxs_user_profile p WHERE u.uid = p.profileid AND uid = '1' LIMIT 0, 1 ( 0.004991) SELECT * FROM U39uxs_modules WHERE dirname = 'catads' ( 0.000412) SELECT * FROM U39uxs_config WHERE (conf_modid = '91') ORDER BY conf_order ASC ( 0.000458) SELECT * FROM U39uxs_config WHERE (conf_modid = '1' AND conf_catid = '3') ORDER BY conf_order ASC ( 0.000414) SELECT * FROM U39uxs_group_permission WHERE (gperm_modid = '1' AND gperm_name = 'module_admin' AND gperm_groupid IN (1,2)) ( 0.00031) SELECT * FROM U39uxs_modules WHERE (hasadmin = '1' AND isactive = '1' AND mid IN (1,2,23,5,6,9,12,95,94,21,18,57,54,32,33,34,36,91,51,78,79,81,82,85)) ORDER BY name ASC ( 0.000389) SELECT * FROM U39uxs_group_permission WHERE (gperm_modid = '1' AND gperm_name = 'system_admin' AND gperm_groupid IN (1,2)) ( 0.000457) SELECT * FROM U39uxs_configcategory WHERE confcat_modid IN (57,5,21,85,78,91,36,12,82,18,32,81,1,51,6,34,79,9,23,33,54) ( 0.000405) SELECT * FROM U39uxs_modules WHERE dirname = 'glossaries' ( 0.000412) SELECT * FROM U39uxs_config WHERE (conf_modid = '85') ORDER BY conf_order ASC ( 0.000466) SELECT categoryID, name FROM U39uxs_lxcategories02 ( 0.000432) SELECT * FROM U39uxs_modules WHERE dirname = 'lexikon' ( 0.000398) SELECT * FROM U39uxs_config WHERE (conf_modid = '78') ORDER BY conf_order ASC ( 0.000415) SELECT categoryID, name FROM U39uxs_lxcategories ( 0.000405) SELECT COUNT(*) FROM U39uxs_catads_ads WHERE uid = '1' ( 0.000298) SELECT groupid, name FROM U39uxs_groups ORDER BY name ASC ( 0.000406) SELECT * FROM U39uxs_modules WHERE dirname = 'news' Queries core SELECT * FROM U39uxs_config WHERE (conf_modid = '1' AND conf_catid = '1') ORDER BY conf_order ASC SELECT sess_data FROM U39uxs_session WHERE sess_id = '77656ccbf6d1a2961f21accf8e7c7614' ( 0.000476) SELECT * FROM U39uxs_users u, U39uxs_user_profile p WHERE u.uid = p.profileid AND uid = '1' LIMIT 0, 1 ( 0.000534) SELECT * FROM U39uxs_modules WHERE dirname = 'catads' ( 0.00036) SELECT * FROM U39uxs_config WHERE (conf_modid = '91') ORDER BY conf_order ASC ( 0.000457) SELECT * FROM U39uxs_config WHERE (conf_modid = '1' AND conf_catid = '3') ORDER BY conf_order ASC ( 0.000319) SELECT COUNT(*) FROM U39uxs_catads_ads WHERE uid = '1' ( 0.000225) SELECT * FROM U39uxs_group_permission WHERE (gperm_modid = '1' AND gperm_name = 'block_read' AND gperm_groupid IN (1,2)) ( 0.00032) SELECT DISTINCT i.instanceid, b.*, i.* FROM U39uxs_block_instance i, U39uxs_newblocks b, U39uxs_block_module_link m WHERE m.block_id=i.instanceid AND i.instanceid IN (17,58,42,127,54,87,134,100,84,85,111,106,113,129,128,115,126,118,122) AND i.visible=1 AND i.bid=b.bid AND b.isactive=1 AND ( (m.module_id=0 AND m.pageid=0) OR (m.module_id=91 AND m.pageid IN (0,0)) ) ORDER BY i.weight,i.instanceid ( 0.000432) SELECT * FROM U39uxs_xoopsnotifications WHERE (not_modid = '91' AND not_category = 'global' AND not_uid = '1') ( 0.00061) SELECT * FROM U39uxs_modules WHERE mid = 91 ( 0.000319) SELECT COUNT(*) FROM U39uxs_catads_ads WHERE uid = '1' ( 0.000179) SELECT * FROM U39uxs_modules WHERE dirname = 'xbs_tags' ( 0.000501) SELECT * FROM U39uxs_config WHERE (conf_modid = '33') ORDER BY conf_order ASC ( 0.000411) select id from U39uxs_tags_index where tags_fname = '/modules/catads/index.php' ( 0.000298) select * from U39uxs_tags_index where id = 4 ( 0.000353) SELECT * FROM U39uxs_modules WHERE mid = 7 ( 0.000346) Total Number of Queries: 17 | Total SQL Generation Time: 0.00614 Queries module DELETE FROM U39uxs_protector_access WHERE expire < UNIX_TIMESTAMP() ( 0.000308) SELECT COUNT(*) FROM U39uxs_protector_access WHERE ip='88.147.214.245' AND request_uri='/modules/catads/index.php' ( 0.00038) SELECT COUNT(*) FROM U39uxs_protector_access WHERE ip='88.147.214.245' ( 0.000273) INSERT INTO U39uxs_protector_access SET ip='88.147.214.245',request_uri='/modules/catads/index.php',expire=UNIX_TIMESTAMP()+'60' ( 0.000398) SELECT COUNT(*) FROM U39uxs_catads_ads WHERE waiting = '1' ( 0.000203) SELECT cat_id, count(*) FROM U39uxs_catads_ads WHERE (waiting = '0' AND published < '1229857231' AND expired > '1229857231') GROUP BY cat_id ( 0.000659) SELECT cat_id, count(*) FROM U39uxs_catads_ads WHERE (published > '1229598031' AND waiting = '0' AND expired > '1229857231' AND published < '1229857231') GROUP BY cat_id ( 0.000429) SELECT * FROM U39uxs_catads_cat ORDER BY weight ( 0.000272) SELECT cat_id, pid FROM U39uxs_catads_cat ( 0.000238) SELECT cat_id, title, img FROM U39uxs_catads_cat WHERE pid = 0 ORDER BY weight ( 0.000301) SELECT * FROM U39uxs_catads_cat WHERE pid =1 ORDER BY weight ( 0.000229) SELECT * FROM U39uxs_catads_cat WHERE pid =2 ORDER BY weight ( 0.000254) SELECT * FROM U39uxs_catads_cat WHERE pid =3 ORDER BY weight ( 0.000262) SELECT COUNT(*) FROM U39uxs_catads_ads WHERE (waiting = '0' AND published < '1229857231' AND expired > '1229857231') ( 0.000411) SELECT * FROM U39uxs_catads_ads WHERE (waiting = '0' AND published < '1229857231' AND expired > '1229857231') ORDER BY published DESC LIMIT 0, 10 ( 0.000834) Total Number of Queries: 15 | Total SQL Generation Time: 0.00545 Queries block SELECT * FROM U39uxs_modules WHERE dirname = 'pm' ( 0.000307) SELECT COUNT(*) FROM U39uxs_priv_msgs WHERE (read_msg = '0' AND to_userid = '1') ( 0.00025) SELECT * FROM U39uxs_smiles ( 0.000442) SELECT cat_id, title FROM U39uxs_catads_cat WHERE pid=0 ORDER BY title ( 0.000331) SELECT * FROM U39uxs_catads_cat WHERE pid=2 ORDER BY title ( 0.000349) SELECT * FROM U39uxs_catads_cat WHERE pid=3 ORDER BY title ( 0.000335) SELECT * FROM U39uxs_catads_cat WHERE pid=1 ORDER BY title ( 0.000364)


Im not sure how to see what queries are used in debug for table xoopsnotifications tho.
Mind anchors

27
trabis
Re: Notifications based on criteria
  • 2008/12/21 11:55

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Quote:

deka87 wrote:

but got a blank page again


The sql code has a bug and I think the conditions are wrong.

Try this:
le="color: #000000"><?php global $xoopsDB; $sql = " SELECT * FROM ".$xoopsDB->prefix('xoopsnotifications')." LEFT JOIN ".$xoopsDB->prefix('user_profile')." ON not_uid = profileid WHERE not_modid = '".intVal($mod_id)."' AND not_itemid = '0' AND not_category = 'global' AND not_event = 'new_ads' AND source_language = ".$xoopsDB->quoteString($ads->getVar('ads_lang1'))." AND target_language = ".$xoopsDB->quoteString($ads->getVar('ads_lang2')); $result = $xoopsDB->query($sql);

28
deka87
Re: Notifications based on criteria
  • 2008/12/21 12:32

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


Ok I have added this in adsmod.php:

le="color: #000000"><?php global $xoopsDB; $sql = " SELECT * FROM ".$xoopsDB->prefix('xoopsnotifications')." LEFT JOIN ".$xoopsDB->prefix('user_profile')." ON not_uid = profileid WHERE not_modid = '".intVal($mod_id)."' AND not_itemid = '0' AND not_category = 'global' AND not_event = 'new_ads' AND source_language = ".$xoopsDB->quoteString($ads->getVar('ads_lang1'))." AND target_language = ".$xoopsDB->quoteString($ads->getVar('ads_lang2')); $result = $xoopsDB->query($sql); $user_list = array(); while($row = $xoopsDB->fetchArray($result)){ $user_list[] = $row['not_uid']; } $notification_handler->triggerEvent('global', 0, 'new_ads', $tags, $user_list);


good news is that it doesn't cause a blank page and the script works just fine. the bad news is that you receive all the notifications anyways no matter what your source and target language are.
Mind anchors

29
trabis
Re: Notifications based on criteria
  • 2008/12/21 12:51

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


OK, problem is again in the query as the profile table does not hold the search values(or does it? where does user_profile come from?).

So we going to this using other method, maybe it will not be the best at performance, but it will look a lot better and I hope it will work just fine.

So to get you user list try this:
le="color: #000000"><?php $profile_handler =& xoops_getmodulehandler('profile','profile'); $criteria = new CriteriaCompo(new Criteria('source_language', $ads->getVar('ads_lang1'))); $searchvars[] = 'source_language'; $criteria->add(new Criteria('target_language', $ads->getVar('ads_lang2'))); $searchvars[] = 'target_language'; list($users, $profiles, $total_users) = $profile_handler->search($criteria, $searchvars); unset($criteria); $user_list = array_keys($users);


I hope you are using profile module from XOOPS 2.3

30
trabis
Re: Notifications based on criteria
  • 2008/12/21 13:01

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Looks like you are using 2.2x from your debug, lol. OOps, got to take another look then.

Login

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits