/modules/faq/controller.php

https://gitlab.com/ilya.webcity/anna · PHP · 288 lines · 193 code · 82 blank · 13 comment · 29 complexity · 1ac64177d64ecd46ca2d7fb80d0d40a8 MD5 · raw file

  1. <?php
  2. class controller_faq extends controller {
  3. public function action_index() {
  4. $logged = $this->core->global['auth']->logged;
  5. if ($logged)
  6. {
  7. $model = LoadModel('faq');
  8. $this->view = 'faq/board.tpl';
  9. $this->data['title'] = "Вопросы преподавателю";
  10. $this->data['title_page'] = 'Вопросы преподавателю';
  11. $this->data['err'] = $this->req['err'];
  12. $this->data['sendok'] = $this->req['sendok'];
  13. $this->data['questions'] = $model->get_questions_list();
  14. $this->data['teachers'] = $model->get_teachers_list();
  15. $this->data['user'] = $this->core->global['auth']->user;
  16. } else {
  17. $this->data['title'] = 'Ошибка авторизации';
  18. $this->view = 'notauthpage.tpl';
  19. }
  20. $this->render();
  21. }
  22. public function action_send() {
  23. $this->view = 'faq/board.tpl';
  24. $logged = $this->core->global['auth']->logged;
  25. if ($logged)
  26. {
  27. $model = LoadModel('faq');
  28. $fuser = $this->core->global['auth']->user['user_id'];
  29. $tuser = mysql_escape_string($this->req['teacher']);
  30. $theme = mysql_escape_string($this->req['theme']);
  31. $ask = mysql_escape_string($this->req['message']);
  32. $r = $model->send($fuser, $tuser, $theme, $ask);
  33. if ($r)
  34. {
  35. $mes = 'Вопрос успешно отправлен на модерацию';
  36. $this->redirect('/faq?sendok=' .$mes);
  37. }
  38. else
  39. {
  40. $mes = 'Вопрос не отправлен!';
  41. $this->redirect('/faq?err=' .$mes);
  42. }
  43. }
  44. $this->render();
  45. }
  46. // Администраторские процедуры
  47. public function action_afaq() {
  48. $logged = $this->core->global['auth']->logged;
  49. if ($logged)
  50. {
  51. $user_type = $this->core->global['auth']->user['user_type'];
  52. if ($user_type == 'admin')
  53. {
  54. // это админ, все ок
  55. $model = LoadModel('faq');
  56. $this->view = 'faq/admin_panel.tpl';
  57. $this->data['title'] = "Вопросы преподавателю";
  58. $this->data['title_page'] = 'Вопросы преподавателю';
  59. $this->data['faqstatusok'] = 'OK!';
  60. }
  61. else
  62. {
  63. // Несанкционированный доступ
  64. $this->data['title'] = 'Отказано в доступе';
  65. $this->view = 'notauthpage.tpl';
  66. }
  67. } else {
  68. $this->data['title'] = 'Ошибка авторизации';
  69. $this->view = 'notauthpage.tpl';
  70. }
  71. $this->render();
  72. }
  73. public function action_aCatchNotPublicFaqCount() {
  74. $logged = $this->core->global['auth']->logged;
  75. if($logged) {
  76. $user_type = $this->core->global['auth']->user['user_type'];
  77. if ($user_type == 'admin') {
  78. // это админ, все ок
  79. $model = LoadModel('faq');
  80. $result = $model->getNotPublicFaqCount();
  81. json($result);
  82. } else {
  83. // Несанкционированный доступ
  84. $this->data['title'] = 'Отказано в доступе';
  85. $this->view = 'notauthpage.tpl';
  86. }
  87. } else {
  88. $this->data['title'] = 'Ошибка авторизации';
  89. $this->view = 'notauthpage.tpl';
  90. }
  91. $this->render();
  92. }
  93. public function action_aGetNotPublicList()
  94. {
  95. $logged = $this->core->global['auth']->logged;
  96. if ($logged)
  97. {
  98. $user_type = $this->core->global['auth']->user['user_type'];
  99. if ($user_type == 'admin')
  100. {
  101. // это админ, все ок
  102. $model = LoadModel('faq');
  103. $result = $model->getList('notpublic');
  104. json($result);
  105. }
  106. else
  107. {
  108. // Несанкционированный доступ
  109. $this->data['title'] = 'Отказано в доступе';
  110. $this->view = 'notauthpage.tpl';
  111. }
  112. } else {
  113. $this->data['title'] = 'Ошибка авторизации';
  114. $this->view = 'notauthpage.tpl';
  115. }
  116. $this->render();
  117. }
  118. public function action_aGetPublicList()
  119. {
  120. $logged = $this->core->global['auth']->logged;
  121. if ($logged)
  122. {
  123. $user_type = $this->core->global['auth']->user['user_type'];
  124. if ($user_type == 'admin')
  125. {
  126. // это админ, все ок
  127. $model = LoadModel('faq');
  128. $result = $model->getList('public');
  129. json($result);
  130. }
  131. else
  132. {
  133. // Несанкционированный доступ
  134. $this->data['title'] = 'Отказано в доступе';
  135. $this->view = 'notauthpage.tpl';
  136. }
  137. } else {
  138. $this->data['title'] = 'Ошибка авторизации';
  139. $this->view = 'notauthpage.tpl';
  140. }
  141. $this->render();
  142. }
  143. public function action_OpenFaq()
  144. {
  145. $logged = $this->core->global['auth']->logged;
  146. if ($logged)
  147. {
  148. $user_type = $this->core->global['auth']->user['user_type'];
  149. if ($user_type == 'admin')
  150. {
  151. // это админ, все ок
  152. $model = LoadModel('faq');
  153. $id = htmlspecialchars($this->req['id']);
  154. $result = $model->getOneFaq($id);
  155. json($result);
  156. }
  157. else
  158. {
  159. // Несанкционированный доступ
  160. $this->data['title'] = 'Отказано в доступе';
  161. $this->view = 'notauthpage.tpl';
  162. }
  163. } else {
  164. $this->data['title'] = 'Ошибка авторизации';
  165. $this->view = 'notauthpage.tpl';
  166. }
  167. $this->render();
  168. }
  169. public function action_saveFaq()
  170. {
  171. $logged = $this->core->global['auth']->logged;
  172. if ($logged)
  173. {
  174. $user_type = $this->core->global['auth']->user['user_type'];
  175. if ($user_type == 'admin')
  176. {
  177. // это админ, все ок
  178. $model = LoadModel('faq');
  179. $inputArray = array(
  180. 'ans_fuser' => (int)htmlspecialchars($this->req['FromU']),
  181. 'ans_tuser' => (int)htmlspecialchars($this->req['ToU']),
  182. 'ans_theme' => htmlspecialchars($this->req['theme']),
  183. 'ans_ask' => htmlspecialchars($this->req['ans_ask']),
  184. 'ans_text' => htmlspecialchars($this->req['ans_text']),
  185. 'ans_public' => (int)htmlspecialchars($this->req['ispublic']),
  186. 'ans_dask' => htmlspecialchars($this->req['dask']),
  187. 'ans_danswer' => htmlspecialchars($this->req['danswer'])
  188. );
  189. $id = (int)htmlspecialchars($this->req['id']);
  190. $result = $model->saveFaq($id, $inputArray);
  191. json($result);
  192. }
  193. else
  194. {
  195. // Несанкционированный доступ
  196. $this->data['title'] = 'Отказано в доступе';
  197. $this->view = 'notauthpage.tpl';
  198. }
  199. } else {
  200. $this->data['title'] = 'Ошибка авторизации';
  201. $this->view = 'notauthpage.tpl';
  202. }
  203. $this->render();
  204. }
  205. }
  206. ?>