AmdaNews.php
2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* @class AmdaNews
*/
class AmdaNews {
public $user, $userdir, $infodir;
public function __construct($user) {
if ($user) {
$this->user = $user;
$this->userdir = USERPATH."/".$user."/";
$this->infodir = HELPPATH."INFO/";
}
}
/**
* Add new info message and mark user dir with newInfo file
*/
public function addInfo($group){
// special dir for group news
if ($group) $this->infodir = BASE_PATH.'help/'.$group.'_INFO/';
else $this->infodir = BASE_PATH.'help/INFO/';
$timeStamp = time();
$stringDate = date("Y-m-d",$timeStamp);
if (!is_dir($this->infodir)) mkdir($this->infodir);
$ff = fopen($this->infodir.'info.'.$timeStamp,'w');
$infoToWrite = $_POST['info'];
if (strpos($infoToWrite,"<a href=") !== false) {
$infoToWrite = str_replace("<a href=","<a target='new' href=", $infoToWrite);
}
fwrite($ff,'<li><b>'.$stringDate.'</b><br/>'.$infoToWrite.PHP_EOL);
fclose($ff);
$userDir = BASE_PATH."data/";
$users = glob($userDir."*");
foreach ($users as $user) {
$file = $user.'/newInfo';
touch($file);
chmod($file, 0775);
}
return array("msg" => "New Info is saved", "success" => true);
}
/**
* Concate individual info messages into one to be shown to user
*/
public function makeInfo($groups){
if (file_exists($this->userdir.'lastLogin')) {
$timeStamp = filemtime($this->userdir.'lastLogin');
$ff = fopen($this->userdir.'INFO','w');
fwrite($ff,'<IMG align="right" SRC="help/images/picto_amda.png"/><br/><h2>AMDA Latest News</h2><br/>');
fclose($ff);
$userGrps = explode(',',strtoupper($groups));
foreach ($userGrps as $grp) {
if (is_dir(HELPPATH.$grp."_INFO")) {
$grpDir = HELPPATH.$grp."_INFO/";
$grpInfoFiles = glob($grpDir."info*");
$grpFileList = array();
foreach ($grpInfoFiles as $file) {
$grpFileList[filemtime($file)] = $file;
}
ksort($grpFileList);
$grpFileList = array_reverse($grpFileList, TRUE);
foreach ($grpFileList as $info) {
if (filemtime($info) > $timeStamp) {
file_put_contents($this->userdir.'INFO', file_get_contents($info), FILE_APPEND);
$NN++;
}
}
}
}
$publicInfoFiles = glob($this->infodir."info*");
$fileList = array();
foreach ($publicInfoFiles as $file) {
$fileList[filemtime($file)] = $file;
}
ksort($fileList);
$fileList = array_reverse($fileList, TRUE);
$NN = 0;
foreach ($fileList as $info) {
if (filemtime($info) > $timeStamp) {
file_put_contents($this->userdir.'INFO', file_get_contents($info), FILE_APPEND);
$NN++;
}
}
if ($NN == 0) {
unlink($this->userdir.'INFO'); // No news
return 0;
}
else return 1;
}
else return 0;
}
}
?>