diff --git a/php/classes/AmdaNews.php b/php/classes/AmdaNews.php index bb79d5a..44c33a7 100644 --- a/php/classes/AmdaNews.php +++ b/php/classes/AmdaNews.php @@ -1,122 +1,120 @@ <?php /** * @class AmdaNews - * @version $Id: AmdaNews.php 2957 2015-06-25 13:40:38Z elena $ - * */ class AmdaNews { - public $user, $userdir, $infodir; + public $user, $userdir, $infodir; - public function __construct($user) { - if ($user) { - $this->user = $user; - $this->userdir = USERPATH."/".$user."/"; - $this->infodir = HELPPATH."INFO/"; - } - } + 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); - - } + 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 inti one to be shown to user +* 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; - } + 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; + } } ?> diff --git a/php/classes/UserMgr.php b/php/classes/UserMgr.php index 36460c5..d876b3d 100644 --- a/php/classes/UserMgr.php +++ b/php/classes/UserMgr.php @@ -554,18 +554,18 @@ class UserMgr // if new info exists it will be shown to : // public => to all // special => to group members -// if (file_exists($this->userdir.'newInfo')) -// { -// $amdaInfo = new AmdaNews($this->user); -// // if status = 0 - it is special info to group members only -// // else to all -// $info = $this->getUserInfo($this->user); -// $status = $amdaInfo->makeInfo($info['group']); -// -// if ($status) $this->isNewInfo = true; -// -// unlink($this->userdir.'newInfo'); -// } + if (file_exists($this->userdir.'newInfo')) + { + $amdaInfo = new AmdaNews($this->user); + // if status = 0 - it is special info to group members only + // else to all + $info = $this->getUserInfo($this->user); + $status = $amdaInfo->makeInfo($info['group']); + + if ($status) $this->isNewInfo = true; + + unlink($this->userdir.'newInfo'); + } touch($this->userdir.'newLogin'); $this->setPath(); -- libgit2 0.21.2