1<?php
2/*
3 * e107 website system
4 *
5 * Copyright (C) 2008-2013 e107 Inc (e107.org)
6 * Released under the terms and conditions of the
7 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
8 *
9 */
10
11require_once('../class2.php');
12
13if (!getperms('O'))
14{
15	e107::redirect('admin');
16	exit;
17}
18
19e107::coreLan('notify', true);
20
21class plugin_notify_admin extends e_admin_dispatcher
22{
23
24	protected $modes = array(
25		'main'		=> array('controller' => 'plugin_notify_admin_ui',
26		'path' 		=> null,
27		'ui' 		=> 'plugin_notify_admin_form_ui', 'uipath' => null)
28	);
29
30	protected $adminMenu = array(
31		'main/config' 		=> array('caption'=> "Email", 'perm' => '0'),
32//		'main/push'		=> array('caption'=> "Push (experimental)", 'perm' => '0')
33	);
34
35	protected $adminMenuAliases = array(
36		'main/edit'	=> 'main/list'
37	);
38
39
40	protected $adminMenuIcon = 'e-notify-24';
41
42	/**
43	 * Navigation menu title
44	 * @var string
45	 */
46	protected $menuTitle = NT_LAN_1;
47
48	function init()
49	{
50		if(e_DEBUG !== true)
51		{
52			unset($this->adminMenu['main/push']);
53		}
54
55
56
57	}
58}
59
60
61
62class plugin_notify_admin_ui extends e_admin_ui
63{
64		protected $pluginTitle = NT_LAN_1;
65
66		protected $pluginName = 'core';
67
68		protected $table = "";
69
70		protected $listQry = "";
71
72		protected $pid = "notify_id";
73
74		protected $perPage = 20;
75
76		protected $batchDelete = true;
77
78		//	protected $displaySettings = array();
79
80		//	protected $disallowPages = array('main/create', 'main/prefs');
81
82
83    	protected  $fields = array();
84
85		//required - default column user prefs
86		protected $fieldpref = array();
87
88
89		// optional, if $pluginName == 'core', core prefs will be used, else e107::getPluginConfig($pluginName);
90		protected $prefs = array(
91	/*		'pref_type'	   				=> array('title'=> 'type', 'type'=>'text', 'data' => 'string', 'validate' => true),
92			'pref_folder' 				=> array('title'=> 'folder', 'type' => 'boolean', 'data' => 'integer'),
93			'pref_name' 				=> array('title'=> 'name', 'type' => 'text', 'data' => 'string', 'validate' => 'regex', 'rule' => '#^[\w]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')*/
94		);
95
96		var $notify_prefs;
97		var $changeList = array();
98		var $pluginConfig = array();
99
100		function init()
101		{
102
103
104			if(!empty($_POST['update']))
105			{
106				if($this-> update())
107				{
108			   //     e107::getMessage()->addSuccess(LAN_UPDATED);
109				}
110				else
111				{
112					e107::getMessage()->addError(LAN_UPDATED_FAILED);
113				}
114
115			}
116
117
118			$pref 	= e107::getPref();
119			$this->notify_prefs = e107::getConfig('notify')->getPref();
120
121			$this->prefCleanup();
122			$this->test();
123
124			$recalibrate = FALSE;
125
126			// load every e_notify.php file.
127			if($pref['e_notify_list'])
128			{
129		        foreach($pref['e_notify_list'] as $val) // List of available e_notify.php files.
130				{
131					//	if (!isset($this->notify_prefs['plugins'][$val]))
132						{
133
134							$this -> notify_prefs['plugins'][$val] = TRUE;
135
136							if (is_readable(e_PLUGIN.$val."/e_notify.php"))
137							{
138								require_once(e_PLUGIN.$val.'/e_notify.php');
139
140								if(class_exists($val."_notify")) // new v2.x
141								{
142									$legacy = 0; // Newe.
143									$config_events = array();
144
145									$data = e107::callMethod($val."_notify", 'config');
146
147									$config_category = str_replace("_menu","",ucfirst($val))." ".LAN_NOTIFY_01;
148
149									foreach($data as $v)
150									{
151										$func = $v['function'];
152										$config_events[$func] = $v['name'];
153									}
154
155								}
156								else
157								{
158									$legacy = 1;	// Legacy Mode.
159								}
160
161						//		foreach ($config_events as $event_id => $event_text)
162						//   		{
163								//	$this -> notify_prefs['event'][$event_id] = array('class' => '255', 'email' => '', 'plugin'=> $val);
164
165						//		}
166								$this->pluginConfig[$val] = array('category' => $config_category, 'events' => $config_events, 'legacy'=> $legacy);
167								$recalibrate = true;
168							}
169						}
170				}
171			}
172
173		//	print_a($this->pluginConfig);
174
175			if ($recalibrate)
176			{
177			//	$s_prefs = $tp -> toDB($this -> notify_prefs);
178			//	$s_prefs = $eArrayStorage -> WriteArray($s_prefs);
179			//	$sql -> db_Update("core", "e107_value='".$s_prefs."' WHERE e107_name='notify_prefs'");
180			}
181		}
182
183
184
185
186
187		function prefCleanup()
188		{
189			$oldPrefs = e107::getEvent()->oldCoreList();
190			$curData = $this->notify_prefs['event'];
191
192			foreach($curData as $k=>$v)
193			{
194				if(isset($oldPrefs[$k]))
195				{
196					$newKey = $oldPrefs[$k];
197					$this->notify_prefs['event'][$newKey] = $v;
198					unset($this->notify_prefs['event'][$k]);
199				}
200
201			}
202
203		}
204
205
206
207
208		function pushPage()
209		{
210
211			e107::getMessage()->addInfo("Under Construction");
212
213
214
215
216		}
217
218
219	function test()
220	{
221		if(!empty($_POST['test']))
222		{
223			$id = key( $_POST['test']);
224			$exampleData = array('id'=>'Test for '.$id, 'data'=>'example data'	);
225			e107::getMessage()->addSuccess('Triggering: '.$id);
226			e107::getEvent()->trigger($id, $exampleData);
227		}
228
229
230	}
231
232
233
234	function configPage()
235	{
236		//global $ns, $rs, $frm, $emessage;
237		$ns = e107::getRender();
238		$frm = e107::getForm();
239		$mes = e107::getMessage();
240
241
242		$events = e107::getEvent()->coreList();
243		$tab = array();
244
245		foreach($events as $k=>$cat)
246		{
247			$text = " <table class='table adminform'>
248        	<colgroup>
249        		<col class='col-label' />
250        		<col class='col-control' />
251        	</colgroup>";
252
253			foreach($cat as $c=>$ev)
254			{
255				$text .= $this -> render_event($c, $ev);
256			}
257			$text .= "</table>";
258
259			$caption = str_replace("_menu","",ucfirst($k))." ".LAN_NOTIFY_01;
260
261			$tab[] = array('caption'=>$caption, 'text' => $text);
262		}
263
264		if(!empty($this->notify_prefs['plugins']))
265		{
266
267			foreach ($this->notify_prefs['plugins'] as $plugin_id => $plugin_settings)
268			{
269	            if(is_readable(e_PLUGIN.$plugin_id.'/e_notify.php'))
270				{
271					$config_category = $this->pluginConfig[$plugin_id]['category'];
272					$legacy = $this->pluginConfig[$plugin_id]['legacy'];
273
274					$text = "<table class='table adminform'>
275			        	<colgroup>
276			        		<col class='col-label' />
277			        		<col class='col-control' />
278			        	</colgroup>";
279					;
280
281					foreach ($this->pluginConfig[$plugin_id]['events'] as $event_id => $event_text)
282					{
283						$text .= $this->render_event($event_id, $event_text, $plugin_id, $legacy);
284					}
285
286					$text .= "</table>\n";
287
288					$tab[] = array('caption'=> $config_category, 'text'=> $text);
289				}
290			}
291		}
292
293
294
295		$text2 = $frm->open('scanform', 'post', e_REQUEST_URL); // <form action='".e_SELF."?results' method='post' id='scanform'>
296		$text2 .= $frm->tabs($tab);
297		$text2 .= "<div class='buttons-bar center'>". $frm->admin_button('update', LAN_UPDATE,'update') . "</div>";
298		$text2 .= $frm->close();
299
300
301	//	$ns -> tablerender(NT_LAN_1, $mes->render() . $text2);
302
303		return $text2;
304//	return;
305
306
307
308	}
309
310
311	function render_event($id, $description, $include='', $legacy = 0)
312	{
313		$tp = e107::getParser();
314		$frm = e107::getForm();
315		$uc = e107::getUserClass();
316		$uc->fixed_classes['email'] = NM_LAN_3;
317		$uc->text_class_link['email'] = 'email';
318
319
320		if(defined($description))
321		{
322			$description = constant($description);
323		}
324
325
326
327		$highlight = varset($_GET['type']) == $id ? " class='text-warning'" : '';
328
329		$text = "
330			<tr>
331				<td title='".$id."'><span{$highlight}>".$description.":</span></td>";
332
333
334
335		if(e_DEBUG)
336		{
337			$text .= "<td>".$id."</td>";
338		}
339
340				$text .= "
341				<td  class='form-inline nowrap'>
342				".$uc->uc_dropdown('event['.$id.'][class]', varset($this->notify_prefs['event'][$id]['class'], e_UC_NOBODY), "nobody,main,admin,member,classes,email","onchange=\"mail_field(this.value,'event_".$id."');\" ");
343
344			if($this -> notify_prefs['event'][$id]['class'] == 'email')
345			{
346            	$disp='display:visible';
347				$value = $tp -> toForm($this -> notify_prefs['event'][$id]['email']);
348			}
349			else
350			{
351            	$disp = "display:none";
352				$value= "";
353			}
354
355			$text .= "<input class='form-control' type='text' style='width:200px;$disp' class='tbox' id='event_".$id."' name='event[".$id."][email]' value=\"".$value."\" />\n";
356
357		$text .= $frm->hidden("event[".$id."][include]", $include);
358		$text .= $frm->hidden("event[".$id."][legacy]", $legacy); // function or method
359
360		if(isset($this->notify_prefs['event'][$id]['class']) && $this->notify_prefs['event'][$id]['class'] != e_UC_NOBODY)
361		{
362			$text .= $frm->button('test['.$id.']', $id, 'confirm', LAN_TEST);
363		}
364
365
366		$text .= "</td>";
367
368
369
370
371		$text .= "
372		</tr>";
373		return $text;
374	}
375
376
377	function update()
378	{
379		$this->changeList = array();
380
381		$active = false;
382
383		foreach ($_POST['event'] as $key => $value)
384		{
385			if ($this -> update_event($key))
386			{
387				$active = true;
388			}
389		}
390
391	//	print_a($this->notify_prefs);
392		/*
393		$s_prefs = $tp -> toDB($this -> notify_prefs);
394		$s_prefs = $eArrayStorage -> WriteArray($s_prefs);
395		if($sql -> db_Update("core", "e107_value='".$s_prefs."' WHERE e107_name='notify_prefs'")!==FALSE)
396		*/
397
398		e107::getConfig()->set('notify',$active)->save(true,true,false);
399		e107::getConfig('notify')->updatePref($this->notify_prefs);
400		if (e107::getConfig('notify')->save(FALSE))
401		{
402			// e107::getAdminLog()->logArrayAll('NOTIFY_01',$this->changeList);
403			return true;
404		}
405		else
406		{
407        	return false;
408		}
409
410	}
411
412
413
414
415
416	function update_event($id)
417	{
418		$changed = FALSE;
419
420		if ($this -> notify_prefs['event'][$id]['class'] != $_POST['event'][$id]['class'])
421		{
422			$this -> notify_prefs['event'][$id]['class'] = $_POST['event'][$id]['class'];
423			$changed = TRUE;
424		}
425		if ($this -> notify_prefs['event'][$id]['email'] != $_POST['event'][$id]['email'])
426		{
427			$this -> notify_prefs['event'][$id]['email'] = $_POST['event'][$id]['email'];
428			$changed = TRUE;
429		}
430
431		$this -> notify_prefs['event'][$id]['include'] 	= $_POST['event'][$id]['include'];
432		$this -> notify_prefs['event'][$id]['legacy'] 	= $_POST['event'][$id]['legacy'];
433
434		unset($this -> notify_prefs['event'][$id]['plugin']);
435		unset($this -> notify_prefs['event'][$id]['type']);
436
437		if ($changed)
438		{
439			$this->changeList[$id] = $this->notify_prefs['event'][$id]['class'].', '.$this->notify_prefs['event'][$id]['email'];
440		}
441		if ($this -> notify_prefs['event'][$id]['class'] != 255)
442		{
443			return TRUE;
444		}
445		else
446		{
447			return FALSE;
448		}
449	}
450}
451
452class plugin_notify_admin_form_ui extends e_admin_form_ui
453{
454
455
456
457}
458
459
460new plugin_notify_admin();
461
462
463require_once(e_ADMIN."auth.php");
464
465e107::getAdminUI()->runPage();
466
467require_once(e_ADMIN."footer.php");
468
469function headerjs()
470{
471
472	$js = "
473	<script type='text/javascript'>
474
475    function mail_field(val,id)
476	{
477    	if(val == 'email')
478		{
479        	document.getElementById(id).style.display ='';
480		}
481        else
482		{
483        	document.getElementById(id).style.display ='none';
484		}
485	}
486
487	</script>";
488
489	return $js;
490}
491
492exit;
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518$e_sub_cat = 'notify';
519
520require_once('auth.php');
521require_once(e_HANDLER.'userclass_class.php');
522
523$frm = e107::getForm();
524
525$nc = new notify_config;
526
527$uc = new user_class;
528$mes = e107::getMessage();
529
530if(!empty($_GET['iframe']))
531{
532	define('e_IFRAME', true);
533}
534
535
536
537if (isset($_POST['update']))
538{
539	if($nc -> update())
540	{
541    	//$message = LAN_UPDATED;
542        //$style = E_MESSAGE_SUCCESS;
543        //$mes->addSuccess(LAN_UPDATED);
544	}
545	else
546	{
547    	//$message = LAN_UPDATED_FAILED;
548		//$style = E_MESSAGE_FAILED;
549		$mes->addError(LAN_UPDATED_FAILED);
550	}
551	//$emessage->add($message, $style);
552
553 //	$ns -> tablerender($message,"<div style='text-align:center'>".$message."</div>");
554}
555
556$nc -> config();
557
558
559class notify_config
560{
561	var $notify_prefs;
562	var $changeList = array();
563	var $pluginConfig = array();
564
565	function __construct()
566	{
567		$pref 	= e107::getPref();
568		$this->notify_prefs = e107::getConfig('notify')->getPref();
569
570		$this->prefCleanup();
571		$this->test();
572
573		$recalibrate = FALSE;
574
575		// load every e_notify.php file.
576		if($pref['e_notify_list'])
577		{
578	        foreach($pref['e_notify_list'] as $val) // List of available e_notify.php files.
579			{
580				//	if (!isset($this->notify_prefs['plugins'][$val]))
581					{
582
583						$this -> notify_prefs['plugins'][$val] = TRUE;
584
585						if (is_readable(e_PLUGIN.$val."/e_notify.php"))
586						{
587							require_once(e_PLUGIN.$val.'/e_notify.php');
588
589							if(class_exists($val."_notify")) // new v2.x
590							{
591								$legacy = 0; // Newe.
592								$config_events = array();
593
594								$data = e107::callMethod($val."_notify", 'config');
595
596								$config_category = str_replace("_menu","",ucfirst($val))."  ".LAN_NOTIFY_01;
597
598								foreach($data as $v)
599								{
600									$func = $v['function'];
601									$config_events[$func] = $v['name'];
602								}
603
604							}
605							else
606							{
607								$legacy = 1;	// Legacy Mode.
608							}
609
610					//		foreach ($config_events as $event_id => $event_text)
611					//   		{
612							//	$this -> notify_prefs['event'][$event_id] = array('class' => '255', 'email' => '', 'plugin'=> $val);
613
614					//		}
615							$this->pluginConfig[$val] = array('category' => $config_category, 'events' => $config_events, 'legacy'=> $legacy);
616							$recalibrate = true;
617						}
618					}
619			}
620		}
621
622	//	print_a($this->pluginConfig);
623
624		if ($recalibrate)
625		{
626		//	$s_prefs = $tp -> toDB($this -> notify_prefs);
627		//	$s_prefs = $eArrayStorage -> WriteArray($s_prefs);
628		//	$sql -> db_Update("core", "e107_value='".$s_prefs."' WHERE e107_name='notify_prefs'");
629		}
630	}
631
632	function prefCleanup()
633	{
634		$oldPrefs = e107::getEvent()->oldCoreList();
635		$curData = $this->notify_prefs['event'];
636
637		foreach($curData as $k=>$v)
638		{
639			if(isset($oldPrefs[$k]))
640			{
641				$newKey = $oldPrefs[$k];
642				$this->notify_prefs['event'][$newKey] = $v;
643				unset($this->notify_prefs['event'][$k]);
644			}
645
646		}
647
648	}
649
650
651	function test()
652	{
653		if(!empty($_POST['test']))
654		{
655			$id = key( $_POST['test']);
656			$exampleData = array('id'=>'Test for '.$id, 'data'=>'example data'	);
657			e107::getMessage()->addSuccess('Triggering: '.$id);
658			e107::getEvent()->trigger($id, $exampleData);
659		}
660
661
662	}
663
664
665
666	function config()
667	{
668		//global $ns, $rs, $frm, $emessage;
669		$ns = e107::getRender();
670		$frm = e107::getForm();
671		$mes = e107::getMessage();
672
673
674		$events = e107::getEvent()->coreList();
675		$tab = array();
676
677		foreach($events as $k=>$cat)
678		{
679			$text = " <table class='table adminform'>
680        	<colgroup>
681        		<col class='col-label' />
682        		<col class='col-control' />
683        	</colgroup>";
684
685			foreach($cat as $c=>$ev)
686			{
687				$text .= $this -> render_event($c, $ev);
688			}
689			$text .= "</table>";
690
691			$caption = str_replace("_menu","",ucfirst($k))." ".LAN_NOTIFY_01;
692
693			$tab[] = array('caption'=>$caption, 'text' => $text);
694		}
695
696		if(!empty($this->notify_prefs['plugins']))
697		{
698
699			foreach ($this->notify_prefs['plugins'] as $plugin_id => $plugin_settings)
700			{
701	            if(is_readable(e_PLUGIN.$plugin_id.'/e_notify.php'))
702				{
703					$config_category = $this->pluginConfig[$plugin_id]['category'];
704					$legacy = $this->pluginConfig[$plugin_id]['legacy'];
705
706					$text = "<table class='table adminform'>
707			        	<colgroup>
708			        		<col class='col-label' />
709			        		<col class='col-control' />
710			        	</colgroup>";
711					;
712
713					foreach ($this->pluginConfig[$plugin_id]['events'] as $event_id => $event_text)
714					{
715						$text .= $this->render_event($event_id, $event_text, $plugin_id, $legacy);
716					}
717
718					$text .= "</table>\n";
719
720					$tab[] = array('caption'=> $config_category, 'text'=> $text);
721				}
722			}
723		}
724
725
726
727		$text2 = $frm->open('scanform', 'post', e_REQUEST_URL); // <form action='".e_SELF."?results' method='post' id='scanform'>
728		$text2 .= $frm->tabs($tab);
729		$text2 .= "<div class='buttons-bar center'>". $frm->admin_button('update', LAN_UPDATE,'update') . "</div>";
730		$text2 .= $frm->close();
731
732
733		$ns -> tablerender(NT_LAN_1, $mes->render() . $text2);
734
735
736	return;
737
738
739// <div>".NT_LAN_2.":</div>
740	/*
741		$text = "
742
743		<form action='".e_SELF."?results' method='post' id='scanform'>
744		    <ul class='nav nav-tabs'>
745    <li class='active'><a href='#core' data-toggle='tab'>Users</a></li>
746    <li><a href='#news' data-toggle='tab'>News</a></li>
747    <li><a href='#mail' data-toggle='tab'>Mail</a></li>
748    <li><a href='#files' data-toggle='tab'>Files</a></li>";
749
750	if(!empty($this->notify_prefs['plugins']))
751	{
752		foreach ($this -> notify_prefs['plugins'] as $id => $var)
753		{
754			$text .= "<li><a href='#notify-".$id."' data-toggle='tab'>".ucfirst($id)."</a></li>";
755		}
756	}
757
758	$text .= "
759    </ul>
760    <div class='tab-content'>
761    <div class='tab-pane active' id='core'>
762		<fieldset id='core-notify-config'>
763		<legend>".NU_LAN_1."</legend>
764        <table class='table adminform'>
765        	<colgroup>
766        		<col class='col-label' />
767        		<col class='col-control' />
768        	</colgroup>
769		";
770
771		$text .= $this -> render_event('usersup', NU_LAN_2);
772		$text .= $this -> render_event('userveri', NU_LAN_3);
773		$text .= $this -> render_event('login', NU_LAN_4);
774		$text .= $this -> render_event('logout', NU_LAN_5);
775		$text .= $this -> render_event('user_xup_', NU_LAN_5);
776
777		$text .= "</table></fieldset>
778		<fieldset id='core-notify-2'>
779        <legend>".NS_LAN_1."</legend>
780        <table class='table adminform'>
781        	<colgroup>
782        		<col class='col-label' />
783        		<col class='col-control' />
784        	</colgroup>";
785
786		$text .= $this -> render_event('flood', NS_LAN_2);
787
788
789		$text .= "</table></fieldset>
790		</div>
791
792
793		<div class='tab-pane' id='news'>
794		<fieldset id='core-notify-3'>
795        <legend>".NN_LAN_1."</legend>
796        <table class='table adminform'>
797        	<colgroup>
798        		<col class='col-label' />
799        		<col class='col-control' />
800        	</colgroup>";
801
802		$text .= $this -> render_event('subnews', NN_LAN_2);
803		$text .= $this -> render_event('newspost', NN_LAN_3);
804		$text .= $this -> render_event('newsupd', NN_LAN_4);
805		$text .= $this -> render_event('newsdel', NN_LAN_5);
806
807		$text .= "</table></fieldset>
808		</div>
809
810
811		<div class='tab-pane' id='mail'>
812		<fieldset id='core-notify-4'>
813        <legend>".NM_LAN_1."</legend>
814        <table class='table adminform'>
815        	<colgroup>
816        		<col class='col-label' />
817        		<col class='col-control' />
818        	</colgroup>";
819
820		$text .= $this -> render_event('maildone', NM_LAN_2);
821
822
823		$text .= "</table></fieldset>
824		</div>
825
826
827		<div class='tab-pane' id='files'>
828		<fieldset id='core-notify-5'>
829        <legend>".NF_LAN_1."</legend>
830        <table class='table adminform'>
831        	<colgroup>
832        		<col class='col-label' />
833        		<col class='col-control' />
834        	</colgroup>";
835
836		$text .= $this -> render_event('fileupload', NF_LAN_2);
837
838		$text .= "</table>
839		</fieldset>
840		</div>";
841
842		if(!empty($this->notify_prefs['plugins']))
843		{
844
845			foreach ($this->notify_prefs['plugins'] as $plugin_id => $plugin_settings)
846			{
847	            if(is_readable(e_PLUGIN.$plugin_id.'/e_notify.php'))
848				{
849					$config_category = $this->pluginConfig[$plugin_id]['category'];
850					$legacy = $this->pluginConfig[$plugin_id]['legacy'];
851
852				//	require(e_PLUGIN.$plugin_id.'/e_notify.php');
853
854					$text .= "<div class='tab-pane' id='notify-".$plugin_id."'>
855					<fieldset id='core-notify-".str_replace(" ","_",$config_category)."'>
856			        <legend>".$config_category."</legend>
857			        <table class='table adminform'>
858			        	<colgroup>
859			        		<col class='col-label' />
860			        		<col class='col-control' />
861			        	</colgroup>";
862					;
863
864					foreach ($this->pluginConfig[$plugin_id]['events'] as $event_id => $event_text)
865					{
866						$text .= $this->render_event($event_id, $event_text, $plugin_id, $legacy);
867					}
868
869					$text .= "</table>
870					</div>";
871				}
872			}
873		}
874
875		$text .= "
876
877		<div class='buttons-bar center'>";
878        $text .= $frm->admin_button('update', LAN_UPDATE,'update');
879		$text .= "
880		</div>
881		</fieldset>
882		</form>
883		";
884
885		$ns -> tablerender(NT_LAN_1, $mes->render() . $text);
886	 */
887
888	}
889
890
891	function render_event($id, $description, $include='', $legacy = 0)
892	{
893		$tp = e107::getParser();
894		$frm = e107::getForm();
895		$uc = e107::getUserClass();
896		$uc->fixed_classes['email'] = NM_LAN_3;
897		$uc->text_class_link['email'] = 'email';
898
899
900		if(defined($description))
901		{
902			$description = constant($description);
903		}
904
905
906
907		$highlight = varset($_GET['type']) == $id ? " class='text-warning'" : '';
908
909		$text = "
910			<tr>
911				<td title='".$id."'><span{$highlight}>".$description.":</span></td>";
912
913
914
915		if(e_DEBUG)
916		{
917			$text .= "<td>".$id."</td>";
918		}
919
920				$text .= "
921				<td  class='form-inline nowrap'>
922				".$uc->uc_dropdown('event['.$id.'][class]', varset($this->notify_prefs['event'][$id]['class'], e_UC_NOBODY), "nobody,main,admin,member,classes,email","onchange=\"mail_field(this.value,'event_".$id."');\" ");
923
924			if($this -> notify_prefs['event'][$id]['class'] == 'email')
925			{
926            	$disp='display:visible';
927				$value = $tp -> toForm($this -> notify_prefs['event'][$id]['email']);
928			}
929			else
930			{
931            	$disp = "display:none";
932				$value= "";
933			}
934
935			$text .= "<input type='text' style='width:200px;$disp' class='tbox' id='event_".$id."' name='event[".$id."][email]' value=\"".$value."\" />\n";
936
937		$text .= $frm->hidden("event[".$id."][include]", $include);
938		$text .= $frm->hidden("event[".$id."][legacy]", $legacy); // function or method
939
940		if(isset($this->notify_prefs['event'][$id]['class']) && $this->notify_prefs['event'][$id]['class'] != e_UC_NOBODY)
941		{
942			$text .= $frm->button('test['.$id.']', $id, 'confirm', LAN_TEST);
943		}
944
945
946		$text .= "</td>";
947
948
949
950
951		$text .= "
952		</tr>";
953		return $text;
954	}
955
956
957	function update()
958	{
959		$this->changeList = array();
960
961		$active = false;
962
963		foreach ($_POST['event'] as $key => $value)
964		{
965			if ($this -> update_event($key))
966			{
967				$active = true;
968			}
969		}
970
971	//	print_a($this->notify_prefs);
972		/*
973		$s_prefs = $tp -> toDB($this -> notify_prefs);
974		$s_prefs = $eArrayStorage -> WriteArray($s_prefs);
975		if($sql -> db_Update("core", "e107_value='".$s_prefs."' WHERE e107_name='notify_prefs'")!==FALSE)
976		*/
977
978		e107::getConfig()->set('notify',$active)->save(true,true,false);
979		e107::getConfig('notify')->updatePref($this->notify_prefs);
980		if (e107::getConfig('notify')->save(FALSE))
981		{
982			// e107::getAdminLog()->logArrayAll('NOTIFY_01',$this->changeList);
983			return true;
984		}
985		else
986		{
987        	return false;
988		}
989
990	}
991
992	function update_event($id)
993	{
994		$changed = FALSE;
995
996		if ($this -> notify_prefs['event'][$id]['class'] != $_POST['event'][$id]['class'])
997		{
998			$this -> notify_prefs['event'][$id]['class'] = $_POST['event'][$id]['class'];
999			$changed = TRUE;
1000		}
1001		if ($this -> notify_prefs['event'][$id]['email'] != $_POST['event'][$id]['email'])
1002		{
1003			$this -> notify_prefs['event'][$id]['email'] = $_POST['event'][$id]['email'];
1004			$changed = TRUE;
1005		}
1006
1007		$this -> notify_prefs['event'][$id]['include'] 	= $_POST['event'][$id]['include'];
1008		$this -> notify_prefs['event'][$id]['legacy'] 	= $_POST['event'][$id]['legacy'];
1009
1010		unset($this -> notify_prefs['event'][$id]['plugin']);
1011		unset($this -> notify_prefs['event'][$id]['type']);
1012
1013		if ($changed)
1014		{
1015			$this->changeList[$id] = $this->notify_prefs['event'][$id]['class'].', '.$this->notify_prefs['event'][$id]['email'];
1016		}
1017		if ($this -> notify_prefs['event'][$id]['class'] != 255)
1018		{
1019			return TRUE;
1020		}
1021		else
1022		{
1023			return FALSE;
1024		}
1025	}
1026}
1027
1028require_once(e_ADMIN.'footer.php');/*
1029function headerjs()
1030{
1031
1032	$js = "
1033	<script type='text/javascript'>
1034
1035    function mail_field(val,id)
1036	{
1037    	if(val == 'email')
1038		{
1039        	document.getElementById(id).style.display ='';
1040		}
1041        else
1042		{
1043        	document.getElementById(id).style.display ='none';
1044		}
1045	}
1046
1047	</script>";
1048
1049	return $js;
1050}*/
1051?>
1052