Commit 0323cf9d85f03c13bac3ccf5c68fdc1ddf5e12ee

Authored by Elena.Budnik
1 parent 0f2c5274

new info

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