<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- $
 * @author :NLP (almotmaiz.net)
 * @copyright :Jun 21, 2008
 * @verison :1.2
 * @license :The amendment does not allow, without taking permission from me personally.
 * @contact : H.Alz3abi@gmail.com (E-Mail ONLY!).
$ -->
<product productid="nlp_notifications_thread" active="1">
	<title>Threads notifications</title>
	<description>show thread read req. as notification in notifications system</description>
	<version>1.2</version>
	<url>http://www.vbulletin.org/forum/showthread.php?t=183128</url>
	<versioncheckurl><![CDATA[http://www.vbulletin.org/forum/misc.php?do=productcheck&pid=nlp_notifications_thread]]></versioncheckurl>
	<dependencies>
		<dependency dependencytype="vbulletin" minversion="3.7.0" maxversion="3.8.99" />
	</dependencies>
	<codes>
		<code version="1.0">
			<installcode><![CDATA[$db->hide_errors();
echo '<center>Adding Table :<strong> nlp_notifications_thread </strong></center><br />';vbflush();
$db->query_write("
	CREATE TABLE `" . TABLE_PREFIX . "nlp_notifications_thread` (
		`id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
		`threadid` INT( 10 ) NOT NULL ,
		`dateline` INT( 10 ) NOT NULL,
		`forumid` INT( 10 ) NOT NULL,
		PRIMARY KEY ( `id`, `threadid` )
	)ENGINE = MYISAM ;
");
$db->show_errors();
echo '<center>Adding Table :<strong> nlp_notifications_read </strong></center>';vbflush();
$db->query_write("
	CREATE TABLE `" . TABLE_PREFIX . "nlp_notifications_read` (
		`userid` INT( 10 ) NOT NULL ,
		`threadid` INT( 10 ) NOT NULL ,
		`dateline` INT( 10 ) NOT NULL
	)ENGINE = MYISAM ;
");
$db->show_errors();]]></installcode>
			<uninstallcode><![CDATA[$db->show_errors();
echo '<center>Remove Table : <strong>nlp_notifications_read, nlp_notifications_thread</strong></center>'; vbflush();
$db->query_write("
	DROP TABLE `" . TABLE_PREFIX . "nlp_notifications_read` ,`" . TABLE_PREFIX . "nlp_notifications_thread`
");
$db->show_errors();]]></uninstallcode>
		</code>
	</codes>
	<templates>
	</templates>
	<plugins>
		<plugin active="1" executionorder="5">
			<title>Threads notifications - fetch notifications in list</title>
			<hookname>notifications_list</hookname>
			<phpcode><![CDATA[if($vbulletin->options['nlp_notifications_active'] AND $vbulletin->userinfo['userid'])
{
	// fetch custom permission (exusers) AND (exusergroupids)
	$NLP['notifications']['usergroupid'] = (in_array($vbulletin->userinfo['usergroupid'], explode(',', $vbulletin->options['nlp_notifications_exusergroups']))) ? true : false;
	$NLP['notifications']['userid'] = (in_array($vbulletin->userinfo['userid'], explode(',', $vbulletin->options['nlp_notifications_exusers']))) ? true : false;
	// fetch user readed threads 
	$notifications_get = $vbulletin->db->query_read("
		SELECT * FROM " . TABLE_PREFIX . "nlp_notifications_read
		WHERE userid = " . $vbulletin->userinfo['userid'] . iif(((THIS_SCRIPT == 'SHOWTHREAD') AND $threadid),'AND threadid =' . $threadid));
	while($notifications_ids = $db->fetch_array($notifications_get))
	{
		$notifications_threadids .= ', ' . $notifications_ids['threadid'];
	}
	foreach (array_keys($vbulletin->forumcache) AS $key => $id)
	{
		if (!($vbulletin->userinfo['forumpermissions'][$id] & $vbulletin->bf_ugp_forumpermissions['canview']) 
		OR !($vbulletin->userinfo['forumpermissions'][$id] & $vbulletin->bf_ugp_forumpermissions['canviewthreads']))
		{
			$notifications_forumids .= ', ' . $id;
		}
	}
	$notifications_thrds = $vbulletin->db->query_read_slave("
		SELECT threadid FROM " . TABLE_PREFIX . "nlp_notifications_thread
		WHERE threadid NOT IN (0$notifications_threadids)
		AND forumid NOT IN (0$notifications_forumids)
		ORDER BY dateline ASC
	");
	$vbulletin->userinfo['nlp_notifications_thread'] = intval($db->num_rows($notifications_thrds));
	$notificationsidf = $db->fetch_array($notifications_thrds);
	$notifications['nlp_notifications_thread'] = array(
			'phrase' => $vbphrase['nlp_notifications_threads'],
			'link'   => ($notificationsidf['threadid'])  ? 'showthread.php?'.$vbulletin->session->vars['sessionurl'].'t=' . $notificationsidf['threadid'] : '',
			'order'  => 15
		);
}]]></phpcode>
		</plugin>
		<plugin active="1" executionorder="5">
			<title>Threads notifications - something happent in SHOWTHREAD</title>
			<hookname>showthread_start</hookname>
			<phpcode><![CDATA[if($vbulletin->options['nlp_notifications_active'])
{
	if(!in_array($threadid, explode(',', $notifications_threadids)) AND $vbulletin->userinfo['userid'])// fix userid = 0 value(insert no need val) : Bug#2
	{
		// if not readed yet ;) => instert into DB thread as readed 
		$vbulletin->db->query_write("
			INSERT INTO `" . TABLE_PREFIX . "nlp_notifications_read` 
			(
				`userid` ,
				`threadid` ,
				`dateline`
			) VALUES (
				'" . $vbulletin->userinfo['userid'] . "', 
				'$threadid', 
				'" . TIMENOW . "'
			)
		");
	}
	if(can_moderate($threadinfo['forumid']) AND !$NLP['notifications']['usergroupid'] AND !$NLP['notifications']['userid'])
	{
		// templates replacing.
		$nlp_notifications_phrase = iif(!in_array($threadid,explode(',', $notifications_threadids)),construct_phrase($vbphrase['nlp_notifications_add_thread']),construct_phrase($vbphrase['nlp_notifications_remove_thread']));
		$vbulletin->templatecache['SHOWTHREAD'] = str_replace(
			'$vbphrase[remove_redirects]</label></div>',
			'$vbphrase[remove_redirects]</label></div>\n<div><label for=\"ao_ntn\"><input type=\"radio\" name=\"do\" id=\"ao_ntn\" value=\"notifications\" />$nlp_notifications_phrase</label></div>',
			$vbulletin->templatecache['SHOWTHREAD']
		);
	}
}]]></phpcode>
		</plugin>
		<plugin active="1" executionorder="5">
			<title>Threads notifications - add,remove notification</title>
			<hookname>threadmanage_action_switch</hookname>
			<phpcode><![CDATA[if($vbulletin->options['nlp_notifications_active'] AND $_REQUEST['do'] == 'notifications')
{
	$forumid = false;
    // only mods with the correct permissions should be able to access this
    if (!can_moderate($threadinfo['forumid']) OR $NLP['notifications']['usergroupid'] OR $NLP['notifications']['userid']) print_no_permission();
    // check data
    $NLP['notifications']['exists']= $vbulletin->db->query_first("
		SELECT * FROM " . TABLE_PREFIX . "nlp_notifications_thread
		WHERE threadid = $threadid
	");
	if(empty($NLP['notifications']['exists']))
	{
		// add thread in notifications list for users
		$vbulletin->db->query_write("
			INSERT INTO " . TABLE_PREFIX . "nlp_notifications_thread (`threadid` ,`dateline`, `forumid`)
			VALUES 
				(
					'$threadid', 
					'" . TIMENOW . "',
					'" . $threadinfo['forumid'] . "'
				)
		");
		// redirect back to thread #$threadid
		eval(print_standard_redirect('redirect_nlp_notifications_thread_add', true, true));
	}else{
		// if notifications exists , remove if from notifications list ;)
		$vbulletin->db->query_write("
			DELETE FROM " . TABLE_PREFIX . "nlp_notifications_thread
			WHERE threadid = $threadid
		");
		$vbulletin->db->query_write("
			DELETE FROM " . TABLE_PREFIX . "nlp_notifications_read
			WHERE threadid = $threadid
		");
		// redirect back to thread #$threadid
		eval(print_standard_redirect('redirect_nlp_notifications_thread_removed', true, true));		
	}  
}]]></phpcode>
		</plugin>
	</plugins>
	<phrases>
		<phrasetype name="Front-End Redirect Messages" fieldname="frontredirect">
			<phrase name="nlp_notifications_thread_add" date="1213951303" username="NLP" version="1.0"><![CDATA[شكراً ، تم إضافة الموضوع الى قائمة التنبيهات بنجاح سيتم تحويلك الى الموضوع بعد قليل]]></phrase>
			<phrase name="nlp_notifications_thread_removed" date="1213952309" username="NLP" version="1.0"><![CDATA[شكراً ، تم إزالة الموضوع من قائمة التنبيهات بنجاح سيتم تحويلك الى الموضوع بعد قليل]]></phrase>
		</phrasetype>
		<phrasetype name="GLOBAL" fieldname="global">
			<phrase name="nlp_notifications_add_thread" date="1214015679" username="NLP" version="1.0"><![CDATA[إضافة الموضوع لقائمة التنبيهات]]></phrase>
			<phrase name="nlp_notifications_remove_thread" date="1214015699" username="NLP" version="1.0"><![CDATA[إزالة الموضوع من قائمة التنبيهات]]></phrase>
			<phrase name="nlp_notifications_threads" date="1214021683" username="NLP" version="1.0"><![CDATA[مواضيع يجب قراءتها]]></phrase>
		</phrasetype>
		<phrasetype name="vBulletin Settings" fieldname="vbsettings">
			<phrase name="setting_nlp_notifications_active_desc" date="1214035311" username="NLP" version="1.0"><![CDATA[هذا الخيار يتيح لك تفعيل المنتج أو تعطيله]]></phrase>
			<phrase name="setting_nlp_notifications_active_title" date="1214035311" username="NLP" version="1.0"><![CDATA[تفعيل المنتج]]></phrase>
			<phrase name="setting_nlp_notifications_exusergroups_desc" date="1214051540" username="NLP" version="1.2"><![CDATA[هذا الخيار يتيح لك حظر مجموعه معينهة من استخدام هذا المنتج , في حال وجود اكثر من مجموعه افصل بينهم بالفاصله ","<br />لتعطيل هذه الخاصية اتركها فارغة او ضع صفر "0"]]></phrase>
			<phrase name="setting_nlp_notifications_exusergroups_title" date="1214051540" username="NLP" version="1.2"><![CDATA[المجموعات الممنوعة]]></phrase>
			<phrase name="setting_nlp_notifications_exusers_desc" date="1214051674" username="NLP" version="1.2"><![CDATA[هذا الخيار يتيح لك منع عضو معين من استخدام هذا المنتج وفي حال وجود اكثر من عضويه افصل بين أرقام العضويات بالفاصله "," <br />لتعطيل هذا الخيار اتركه فارغ أو اضف رقم "0"]]></phrase>
			<phrase name="setting_nlp_notifications_exusers_title" date="1214051674" username="NLP" version="1.2"><![CDATA[العضويات الممنوعه]]></phrase>
			<phrase name="settinggroup_nlp_notifications" date="1214035231" username="NLP" version="1.0"><![CDATA[إعدادات منتج  عرض المواضيع على شكل تنبيهات]]></phrase>
		</phrasetype>
	</phrases>
	<options>
		<settinggroup name="nlp_notifications" displayorder="65535">
			<setting varname="nlp_notifications_active" displayorder="10">
				<datatype>integer</datatype>
				<optioncode>yesno</optioncode>
				<defaultvalue>1</defaultvalue>
			</setting>
			<setting varname="nlp_notifications_exusergroups" displayorder="20">
				<datatype>free</datatype>
			</setting>
			<setting varname="nlp_notifications_exusers" displayorder="30">
				<datatype>free</datatype>
			</setting>
		</settinggroup>
	</options>
	<helptopics>
	</helptopics>
	<cronentries>
	</cronentries>
	<faqentries>
	</faqentries>
</product>