api.announcements.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. <?php
  2. /**
  3. * Ubilling user announcements basic class
  4. */
  5. class Announcements {
  6. /**
  7. * Contains current user login
  8. *
  9. * @var string
  10. */
  11. protected $myLogin = '';
  12. /**
  13. * Contains Announce ID from $_GET
  14. *
  15. * @var string
  16. */
  17. protected $ann_id = '';
  18. /**
  19. * Contains Announce FOR from $_GET
  20. *
  21. * @var string
  22. */
  23. protected $ann_for = 'USERS';
  24. /**
  25. * Contains log parametr
  26. *
  27. * @var string
  28. */
  29. protected $log_register = '';
  30. /**
  31. * Contains admiface #_GET parametr
  32. *
  33. * @var string
  34. */
  35. protected $admiface = '';
  36. /**
  37. * Contains Databases announcements table
  38. *
  39. * @var string
  40. */
  41. protected $announcementsTable = 'zbsannouncements';
  42. /**
  43. * Contains Databases history table
  44. *
  45. * @var string
  46. */
  47. protected $historyTable = 'zbsannhist';
  48. /**
  49. * Contains admns Name as admin_login => admin_name
  50. *
  51. * @var array
  52. */
  53. protected $adminsName = array();
  54. /**
  55. * Contains all announces as id => array (public, type, title, text)
  56. *
  57. * @var array
  58. */
  59. protected $announcesAvaible = array();
  60. /**
  61. * Contains all announces history as [annid] => Array ( parametr => Array ( [login] => $value))
  62. *
  63. * @var array
  64. */
  65. protected $announcesHistory = array();
  66. /**
  67. * Contains announces history count as annid => count
  68. *
  69. * @var array
  70. */
  71. protected $announcesHistoryCount = array();
  72. /**
  73. * Contains current intro text
  74. *
  75. * @var string
  76. */
  77. protected $introText = '';
  78. /**
  79. * System caching instance placeholder
  80. *
  81. * @var object
  82. */
  83. protected $cache = '';
  84. /**
  85. * Caching timeout
  86. *
  87. * @var int
  88. */
  89. protected $cacheTime = 2592000; //month by default
  90. /**
  91. * Contains default announcements cache key name
  92. */
  93. const CACHE_KEY_ANN = 'ANNOUNCEMENTS';
  94. /**
  95. * Contains default announcements viewed cache key name
  96. */
  97. const CACHE_KEY_ADMAQ = 'ADMACQUAINTED';
  98. /**
  99. * Contains intro text storage key name
  100. */
  101. const INTRO_KEY = 'ZBS_INTRO';
  102. /**
  103. * Other predefined constants
  104. */
  105. const URL_ME = '?module=announcements';
  106. const EX_ID_NO_EXIST = 'NO_EXISTING_ID_RECEIVED';
  107. public function __construct() {
  108. $this->initMessages();
  109. $this->setLogin();
  110. $this->initCache();
  111. $this->setAnnounceFor();
  112. $this->setAnnounceId();
  113. $this->loadAdminsName();
  114. $this->avaibleAnnouncementsCached();
  115. $this->loadAnnouncesHistoryCached();
  116. $this->loadIntroText();
  117. }
  118. /**
  119. * Inits system messages helper object for further usage
  120. *
  121. * @return void
  122. */
  123. protected function initMessages() {
  124. $this->messages = new UbillingMessageHelper();
  125. }
  126. /**
  127. * Sets current user login
  128. *
  129. * @return void
  130. */
  131. protected function setLogin() {
  132. $this->myLogin = whoami();
  133. }
  134. /**
  135. * Initalizes system cache object
  136. *
  137. * @return void
  138. */
  139. protected function initCache() {
  140. $this->cache = new UbillingCache();
  141. }
  142. /**
  143. * Flushes precached data
  144. *
  145. * @return void
  146. */
  147. protected function flushCache() {
  148. $this->cache->delete(self::CACHE_KEY_ANN);
  149. $this->cache->delete(self::CACHE_KEY_ADMAQ);
  150. }
  151. /**
  152. * Initalizes $ann_for
  153. *
  154. * @return void
  155. */
  156. protected function setAnnounceFor() {
  157. if (wf_CheckGet(array('admiface')) OR ( (@$_GET['module'] == 'taskbar') OR ! isset($_GET['module']))) {
  158. $this->ann_for = 'ADMINS';
  159. $this->admiface = '&admiface=true';
  160. $this->announcementsTable = 'admannouncements';
  161. $this->historyTable = 'admacquainted';
  162. $this->log_register = 'ADM ';
  163. }
  164. }
  165. /**
  166. * Initalizes $ann_id
  167. *
  168. * @return void
  169. */
  170. protected function setAnnounceId() {
  171. if (wf_CheckGet(array('ann_id'))) {
  172. $this->ann_id = vf($_GET['ann_id'], 3);
  173. }
  174. }
  175. /**
  176. * Loads admis Name
  177. *
  178. * @return void
  179. */
  180. protected function loadAdminsName() {
  181. @$employeeLogins = unserialize(ts_GetAllEmployeeLoginsCached());
  182. if (!empty($employeeLogins)) {
  183. foreach ($employeeLogins as $login => $name) {
  184. $this->adminsName[$login] = $name;
  185. }
  186. }
  187. }
  188. /**
  189. * Init admin Name
  190. *
  191. * @param string $admin
  192. * @return void
  193. */
  194. protected function initAdminName($admin) {
  195. $result = '';
  196. if (!empty($admin)) {
  197. $result = (isset($this->adminsName[$admin])) ? $this->adminsName[$admin] : $admin;
  198. }
  199. return ($result);
  200. }
  201. /**
  202. * Loads All avaible Announcements from cache
  203. *
  204. * @return array
  205. */
  206. protected function avaibleAnnouncementsCached() {
  207. $cachedAnnouncements = $this->cache->get(self::CACHE_KEY_ANN, $this->cacheTime);
  208. if (empty($cachedAnnouncements)) {
  209. $cachedAnnouncements = array();
  210. }
  211. if (isset($cachedAnnouncements[$this->announcementsTable])) {
  212. $this->announcesAvaible = $cachedAnnouncements[$this->announcementsTable];
  213. } else {
  214. $ann_arr = $this->loadAvaibleAnnouncements();
  215. if (!empty($ann_arr)) {
  216. foreach ($ann_arr as $key => $data) {
  217. $this->announcesAvaible[$data['id']]['public'] = @$data['public'];
  218. $this->announcesAvaible[$data['id']]['type'] = @$data['type'];
  219. $this->announcesAvaible[$data['id']]['title'] = $data['title'];
  220. $this->announcesAvaible[$data['id']]['text'] = $data['text'];
  221. }
  222. }
  223. $cachedAnnouncements[$this->announcementsTable] = $this->announcesAvaible;
  224. $this->cache->set(self::CACHE_KEY_ANN, $cachedAnnouncements, $this->cacheTime);
  225. }
  226. }
  227. /**
  228. * Loads All avaible Announcements from databases
  229. *
  230. * @return array
  231. */
  232. public function loadAvaibleAnnouncements() {
  233. $query = "SELECT * from `" . $this->announcementsTable . "` ORDER by `id` ASC";
  234. $result = simple_queryall($query);
  235. return ($result);
  236. }
  237. /**
  238. * Loads all avaible hystory results from cache
  239. *
  240. * @return array announcesHistory
  241. * @return array announcesHistoryCount
  242. */
  243. protected function loadAnnouncesHistoryCached($ann_id = '') {
  244. // Initialises ann_id
  245. $ann_id = ($ann_id) ? $ann_id : $this->ann_id;
  246. if (isset($this->announcesAvaible[$ann_id])) {
  247. $votes_arr = $this->loadAnnounceHistory($ann_id);
  248. if (!empty($votes_arr)) {
  249. foreach ($votes_arr as $data) {
  250. $this->announcesHistory[$data['annid']]['id'][$data['login']] = $data['id'];
  251. $this->announcesHistory[$data['annid']]['date'][$data['login']] = $data['date'];
  252. }
  253. // Count Announces History votes
  254. $this->announcesHistoryCount[$data['annid']] = count($this->announcesHistory[$data['annid']]['id']);
  255. }
  256. }
  257. }
  258. /**
  259. * Loads all avaible votes result from databases
  260. *
  261. * @return array
  262. */
  263. public function loadAnnounceHistory($ann_id) {
  264. if ($this->ann_for != 'ADMINS') {
  265. $query = "SELECT * FROM `" . $this->historyTable . "` WHERE `annid` = '" . $ann_id . "'";
  266. } else {
  267. $query = "SELECT *,`admin` as `login` FROM `" . $this->historyTable . "` WHERE `annid` = '" . $ann_id . "'";
  268. }
  269. $result = simple_queryall($query);
  270. return ($result);
  271. }
  272. /**
  273. * Create Announce on database
  274. *
  275. * @param int $public, $type, $title, $text
  276. * @return void
  277. */
  278. protected function createAnnounce($title, $text, $public, $type) {
  279. $ann_id = '';
  280. $public = vf($public, 3);
  281. $type = vf($type);
  282. $title = mysql_real_escape_string($title);
  283. $text = mysql_real_escape_string($text);
  284. if ($this->ann_for != 'ADMINS') {
  285. $query = "INSERT INTO `zbsannouncements` (`id`,`public`,`type`,`title`,`text`) VALUES
  286. (NULL, '" . $public . "', '" . $type . "', '" . $title . "', '" . $text . "'); ";
  287. } else {
  288. $query = "INSERT INTO `admannouncements` (`id`,`title`,`text`) VALUES
  289. (NULL, '" . $title . "', '" . $text . "'); ";
  290. }
  291. nr_query($query);
  292. $query_ann_id = "SELECT LAST_INSERT_ID() as id";
  293. $ann_id = simple_query($query_ann_id);
  294. $ann_id = $ann_id['id'];
  295. log_register("ANNOUNCEMENT " . $this->log_register . "CREATE [" . $ann_id . "]");
  296. $this->flushCache();
  297. return ($ann_id);
  298. }
  299. /**
  300. * Change Announce data on database
  301. *
  302. * @param int $ann_id, array $new_ann_data
  303. * @return void
  304. */
  305. protected function editAnnounce($ann_id, $new_ann_data) {
  306. $old_ann_data = $this->announcesAvaible[$ann_id];
  307. $diff_data = array_diff_assoc($new_ann_data, $old_ann_data);
  308. if (!empty($diff_data)) {
  309. foreach ($diff_data as $field => $value) {
  310. simple_update_field($this->announcementsTable, $field, $value, "WHERE `id`='" . $ann_id . "'");
  311. }
  312. log_register("ANNOUNCEMENT " . $this->log_register . "EDIT [" . $ann_id . "]");
  313. $this->flushCache();
  314. }
  315. }
  316. /**
  317. * Delete Announce from database
  318. *
  319. * @param int $ann_id
  320. * @return void
  321. */
  322. protected function deleteAnnounce($ann_id) {
  323. $this->deleteAnnounceHistory($ann_id);
  324. $query = "DELETE FROM `" . $this->announcementsTable . "` WHERE `id` ='" . $ann_id . "'";
  325. nr_query($query);
  326. $this->flushCache();
  327. }
  328. /**
  329. * Delete Announce History from database
  330. *
  331. * @param int $ann_id
  332. * @return void
  333. */
  334. protected function deleteAnnounceHistory($ann_id) {
  335. $query = "DELETE FROM `" . $this->historyTable . "` WHERE `annid` = '" . $ann_id . "'";
  336. nr_query($query);
  337. }
  338. /**
  339. * Deletes all data about Announce from database by ID
  340. *
  341. * @param int $ann_id
  342. * @return void
  343. */
  344. public function deleteAnnounceData() {
  345. if (isset($this->announcesAvaible[$this->ann_id])) {
  346. $this->deleteAnnounce($this->ann_id);
  347. log_register("ANNOUNCEMENT " . $this->log_register . "DELETE [" . $this->ann_id . "]");
  348. }
  349. rcms_redirect(self::URL_ME . $this->admiface);
  350. }
  351. /**
  352. * updates some existing announcement in database
  353. *
  354. * @param int $id existing announcement ID
  355. *
  356. * @return void
  357. */
  358. public function controlAnn(array $announcements_data) {
  359. $result = '';
  360. $message_warn = '';
  361. if (!empty($announcements_data)) {
  362. // Check announcements name
  363. if (!empty($announcements_data['title'])) {
  364. $name = ($announcements_data['title']);
  365. } else {
  366. $message_warn .= $this->messages->getStyledMessage(__('Title cannot be empty'), 'warning');
  367. }
  368. // Check that we dont have warning message and create Announce
  369. if (empty($message_warn) and @ $_POST['createann']) {
  370. $ann_id = $this->createAnnounce($name, $announcements_data['text'], @$announcements_data['public'], @$announcements_data['type']);
  371. // Check that we create Announce, get his $ann_id and redirect to module
  372. if ($ann_id) {
  373. rcms_redirect(self::URL_ME . $this->admiface);
  374. }
  375. } elseif (empty($message_warn) and @ $_POST['editann']) {
  376. if ($this->ann_for != 'ADMINS') {
  377. $new_ann_data = array('title' => $name, 'text' => $announcements_data['text'], 'public' => $announcements_data['public'], 'type' => $announcements_data['type']);
  378. } else {
  379. $new_ann_data = array('title' => $name, 'text' => $announcements_data['text']);
  380. }
  381. $this->editAnnounce($this->ann_id, $new_ann_data);
  382. rcms_redirect(self::URL_ME . '&action=edit&ann_id=' . $this->ann_id . $this->admiface);
  383. }
  384. } else {
  385. $result .= $this->messages->getStyledMessage(__('Poll data cannot be empty '), 'warning');
  386. }
  387. $result .= $message_warn;
  388. return ($result);
  389. }
  390. /**
  391. * returns announcement edit form
  392. *
  393. * @param int $id existing announcement ID
  394. *
  395. * @return string
  396. */
  397. public function renderForm() {
  398. $states = array(1 => __('Yes'), 0 => __('No'));
  399. $types = array("text" => __('Text'), "html" => __('HTML'));
  400. $sup = wf_tag('sup') . '*' . wf_tag('sup', true);
  401. $result = '';
  402. if (!empty($this->ann_id)) {
  403. $ann_action = 'editann';
  404. $result .= wf_modal(web_icon_search() . ' ' . __('Preview'), __('Preview'), $this->preview($this->ann_id), 'ubButton', '800', '400');
  405. $result .= wf_delimiter();
  406. $inputs = wf_TextInput($ann_action . '[title]', __('Title'), $this->announcesAvaible[$this->ann_id]['title'], true, 40);
  407. $inputs .= __('Text') . ' (HTML)' . $sup . wf_tag('br');
  408. $inputs .= wf_TextArea($ann_action . '[text]', '', $this->announcesAvaible[$this->ann_id]['text'], true, '60x10');
  409. // Check that we dont use admin parametr
  410. if ($this->ann_for != 'ADMINS') {
  411. $inputs .= wf_Selector($ann_action . '[public]', $states, __('Public'), $this->announcesAvaible[$this->ann_id]['public'], false);
  412. $inputs .= wf_Selector($ann_action . '[type]', $types, __('Type'), $this->announcesAvaible[$this->ann_id]['type'], false);
  413. }
  414. $inputs .= wf_delimiter();
  415. $inputs .= wf_Submit(__('Save'));
  416. $result .= wf_Form("", 'POST', $inputs, 'glamour');
  417. return ($result);
  418. } else {
  419. $ann_action = 'createann';
  420. $inputs = wf_TextInput($ann_action . '[title]', __('Title'), '', true, 40);
  421. $inputs .= __('Text') . ' (HTML)' . $sup . wf_tag('br');
  422. $inputs .= wf_TextArea($ann_action . '[text]', '', '', true, '60x10');
  423. // Check that we dont use admin parametr
  424. if ($this->ann_for != 'ADMINS') {
  425. $inputs .= wf_Selector($ann_action . '[public]', $states, __('Public'), '', false);
  426. $inputs .= wf_Selector($ann_action . '[type]', $types, __('Type'), '', false);
  427. }
  428. $inputs .= wf_delimiter();
  429. $inputs .= wf_Submit(__('Create'));
  430. $result = wf_Form("", 'POST', $inputs, 'glamour');
  431. return ($result);
  432. }
  433. }
  434. /**
  435. * Loads current intro text from database
  436. *
  437. * @return void
  438. */
  439. protected function loadIntroText() {
  440. $this->introText = zb_StorageGet(self::INTRO_KEY);
  441. }
  442. /**
  443. * Renders intro text editing form
  444. *
  445. * @return string
  446. */
  447. protected function introEditForm() {
  448. $result = '';
  449. $inputs = wf_HiddenInput('newzbsintro', 'true');
  450. $inputs .= __('Text') . ' (HTML)' . wf_tag('br');
  451. $inputs .= wf_TextArea('newzbsintrotext', '', $this->introText, true, '70x15');
  452. $inputs .= wf_Submit(__('Save'));
  453. $result = wf_Form('', 'POST', $inputs, 'glamour');
  454. return ($result);
  455. }
  456. /**
  457. * Stores new intro text in database
  458. *
  459. * @param string $data
  460. *
  461. * @return void
  462. */
  463. public function saveIntroText($data) {
  464. zb_StorageSet(self::INTRO_KEY, $data);
  465. log_register('ANNOUNCEMENT INTRO UPDATE');
  466. }
  467. /**
  468. * Renders module controls
  469. *
  470. * @return string
  471. */
  472. public function panel() {
  473. $result = '';
  474. // Add backlink
  475. if (wf_CheckGet(array('action')) OR wf_CheckGet(array('show_acquainted'))) {
  476. $result .= wf_BackLink(self::URL_ME . $this->admiface);
  477. } else {
  478. if (cfr('ZBSANNCONFIG')) {
  479. $result .= wf_Link(self::URL_ME . '&action=create' . $this->admiface, web_icon_create() . ' ' . __('Create'), false, 'ubButton');
  480. }
  481. }
  482. if (!wf_CheckGet(array('show_acquainted')) AND wf_CheckGet(array('admiface'))) {
  483. $result .= wf_Link(self::URL_ME, wf_img('skins/zbsannouncements.png') . ' ' . __('Userstats announcements'), false, 'ubButton') . ' ';
  484. }
  485. if (!wf_CheckGet(array('show_acquainted')) AND ! wf_CheckGet(array('admiface'))) {
  486. if (cfr('ZBSANNCONFIG')) {
  487. $result .= wf_modalAuto(wf_img('skins/zbsannouncements.png') . ' ' . __('Userstats intro'), __('Userstats intro'), $this->introEditForm(), 'ubButton');
  488. }
  489. if (!wf_CheckGet(array('show_acquainted'))) {
  490. $result .= wf_Link(self::URL_ME . '&admiface=true', wf_img('skins/admannouncements.png') . ' ' . __('Administrators announcements'), false, 'ubButton');
  491. }
  492. }
  493. return ($result);
  494. }
  495. /**
  496. * returns announcement preview
  497. *
  498. * @param int $id existing announcement ID
  499. *
  500. * @return string
  501. */
  502. protected function preview($id) {
  503. $result = '';
  504. if (isset($this->announcesAvaible[$id])) {
  505. if (!empty($this->announcesAvaible[$id]['title'])) {
  506. $result = wf_tag('h3', false, 'row2', '') . $this->announcesAvaible[$id]['title'] . '&nbsp;' . wf_tag('h3', true);
  507. }
  508. $previewtext = $this->announcesAvaible[$id]['text'];
  509. $result .= nl2br($previewtext);
  510. $result .= wf_delimiter();
  511. }
  512. return ($result);
  513. }
  514. /**
  515. * Loads users address and realname data for further usage
  516. *
  517. * @return void
  518. */
  519. protected function loadUsersData() {
  520. $this->allAddress = zb_AddressGetFulladdresslistCached();
  521. $this->allRealNames = zb_UserGetAllRealnames();
  522. }
  523. /**
  524. * Renders list of users which acquainted with some announcement
  525. *
  526. * @param int $id
  527. *
  528. * @return string
  529. */
  530. public function renderAcquaintedUsers() {
  531. $opts = '"order": [[ 0, "desc" ]]';
  532. if ($this->ann_for != 'ADMINS') {
  533. $columns = array('ID', 'Login', 'Address', 'Real Name', 'Date');
  534. } else {
  535. $columns = array('ID', 'Admin', 'Date');
  536. }
  537. $result = wf_JqDtLoader($columns, self::URL_ME . '&ajaxannusers=true&ann_id=' . $this->ann_id . $this->admiface, false, 'Users', 100, $opts);
  538. return ($result);
  539. }
  540. /**
  541. * Renders list of users which acquainted with some announcement
  542. *
  543. * @param int $id
  544. *
  545. * @return string
  546. */
  547. public function ajaxAvaibAcquaintedUsers() {
  548. $json = new wf_JqDtHelper();
  549. if (isset($this->announcesHistory[$this->ann_id])) {
  550. $this->loadUsersData();
  551. foreach ($this->announcesHistory[$this->ann_id]['id'] as $login => $value) {
  552. $data[] = $this->announcesHistory[$this->ann_id]['id'][$login];
  553. if ($this->ann_for != 'ADMINS') {
  554. $data[] = wf_Link('?module=userprofile&username=' . $login, web_profile_icon() . ' ' . $login);
  555. $data[] = @$this->allAddress[$login];
  556. $data[] = @$this->allRealNames[$login];
  557. } else {
  558. $data[] = $this->initAdminName($login);
  559. }
  560. $data[] = $this->announcesHistory[$this->ann_id]['date'][$login];
  561. $json->addRow($data);
  562. unset($data);
  563. }
  564. }
  565. $json->getJson();
  566. }
  567. /**
  568. * Renders Announces module control panel interface
  569. *
  570. * @return string
  571. */
  572. public function renderAvaibleAnnouncements() {
  573. $opts = '"order": [[ 0, "desc" ]]';
  574. if ($this->ann_for != 'ADMINS') {
  575. $columns = array('ID', 'Title', 'Status', 'Type', 'Text', 'Acquainted', 'Actions');
  576. } else {
  577. $columns = array('ID', 'Title', 'Text', 'Acquainted', 'Actions');
  578. }
  579. $result = wf_JqDtLoader($columns, self::URL_ME . '&ajaxavaibleann=true' . $this->admiface, false, 'Announcements', 100, $opts);
  580. return ($result);
  581. }
  582. /**
  583. * Renders json formatted data about Announces
  584. *
  585. * @return void
  586. */
  587. public function ajaxAvaibleAnnouncements() {
  588. $json = new wf_JqDtHelper();
  589. if (!empty($this->announcesAvaible)) {
  590. foreach ($this->announcesAvaible as $ann_id => $announce) {
  591. $this->loadAnnouncesHistoryCached($ann_id);
  592. $actionLinks = '';
  593. if (cfr('ZBSANNCONFIG')) {
  594. $actionLinks .= wf_JSAlert(self::URL_ME . '&action=delete&ann_id=' . $ann_id . $this->admiface, web_delete_icon(), __('Removing this may lead to irreparable results'));
  595. $actionLinks .= wf_JSAlert(self::URL_ME . '&action=edit&ann_id=' . $ann_id . $this->admiface, web_edit_icon(), __('Are you serious'));
  596. }
  597. $actionLinks .= wf_modal(wf_img('skins/icon_search_small.gif', __('Preview')), __('Preview'), $this->preview($ann_id), '', '800', '400');
  598. if (isset($this->announcesHistoryCount[$ann_id])) {
  599. $announcesHistory = wf_Link(self::URL_ME . '&show_acquainted=true&ann_id=' . $ann_id . $this->admiface, $this->announcesHistoryCount[$ann_id]);
  600. } else {
  601. $announcesHistory = 0;
  602. }
  603. if (strlen($announce['text']) > 100) {
  604. $textPreview = mb_substr(strip_tags($announce['text']), 0, 100, 'utf-8') . '...';
  605. } else {
  606. $textPreview = strip_tags($announce['text']);
  607. }
  608. $data[] = $ann_id;
  609. $data[] = strip_tags($announce['title']);
  610. if ($this->ann_for != 'ADMINS') {
  611. $data[] = web_bool_led($announce['public']);
  612. $data[] = $announce['type'];
  613. }
  614. $data[] = $textPreview;
  615. $data[] = $announcesHistory;
  616. $data[] = $actionLinks;
  617. $json->addRow($data);
  618. unset($data);
  619. }
  620. }
  621. $json->getJson();
  622. }
  623. }
  624. /**
  625. * Ubilling administrator announcements basic class
  626. */
  627. class AdminAnnouncements extends Announcements {
  628. public function __construct() {
  629. $this->setLogin();
  630. $this->initCache();
  631. $this->setAnnounceFor();
  632. $this->avaibleAnnouncementsCached();
  633. }
  634. /**
  635. * gets poll that user not voted yet
  636. *
  637. * @return array
  638. */
  639. protected function loadAnnouncementsForAcquainted() {
  640. $result = array();
  641. $cachedResult = $this->cache->get(self::CACHE_KEY_ADMAQ, $this->cacheTime);
  642. if (empty($cachedResult)) {
  643. $cachedResult = array();
  644. }
  645. if (isset($cachedResult[$this->myLogin])) {
  646. $result = $cachedResult[$this->myLogin];
  647. } else {
  648. $query = "SELECT * FROM `admannouncements` WHERE `id` NOT IN (SELECT `annid` FROM `admacquainted` "
  649. . "WHERE `admin` = '" . $this->myLogin . "') ";
  650. $result = simple_queryall($query);
  651. $cachedResult[$this->myLogin] = $result;
  652. $this->cache->set(self::CACHE_KEY_ADMAQ, $cachedResult, $this->cacheTime);
  653. }
  654. return ($result);
  655. }
  656. /**
  657. * Renders current user announcements if required
  658. *
  659. * @return string
  660. */
  661. public function showAnnouncements() {
  662. $result = '';
  663. $AnnouncementsForAcquainted = $this->loadAnnouncementsForAcquainted();
  664. if (!empty($AnnouncementsForAcquainted)) {
  665. if (!empty($this->myLogin)) {
  666. foreach ($AnnouncementsForAcquainted as $io => $each) {
  667. $result .= $this->preview($each['id']);
  668. $result .= wf_Link('?module=taskbar&setacquainted=' . $each['id'], wf_img('skins/icon_ok.gif') . ' ' . __('Acquainted'), true, 'ubButton');
  669. }
  670. }
  671. }
  672. if (!empty($result)) {
  673. $result = wf_modalOpened(__('Announcements'), $result, '800', '600');
  674. }
  675. return ($result);
  676. }
  677. /**
  678. * Sets some admiface announcement as read
  679. *
  680. * @param int $announcementId
  681. *
  682. * @return void
  683. */
  684. public function setAcquainted($announcementId) {
  685. $announcementId = vf($announcementId, 3);
  686. $curDate = curdatetime();
  687. $loginFiltered = mysql_real_escape_string($this->myLogin);
  688. if (!empty($loginFiltered)) {
  689. $query = "INSERT INTO `admacquainted` (`id`,`date`,`admin`,`annid`) VALUES "
  690. . "(NULL, '" . $curDate . "','" . $loginFiltered . "','" . $announcementId . "');";
  691. nr_query($query);
  692. log_register("ANNOUNCEMENT ADM READ [" . $announcementId . "]");
  693. $this->flushCache();
  694. }
  695. }
  696. }
  697. ?>