PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/include/admin/genControlPanel.php

http://opixido-ocms.googlecode.com/
PHP | 327 lines | 221 code | 75 blank | 31 comment | 28 complexity | 3859d0cd165f7e145da471f4d16a7d73 MD5 | raw file
Possible License(s): GPL-3.0, Apache-2.0, BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. #
  3. # This file is part of oCMS.
  4. #
  5. # oCMS is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # oCMS is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with oCMS. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. # @author Celio Conort / Opixido
  19. # @copyright opixido 2009
  20. # @link http://code.google.com/p/opixido-ocms/
  21. # @package ocms
  22. #
  23. class genControlPanel {
  24. function __construct($admin = false) {
  25. $strAction = $this->GlobalAction();
  26. if (!empty($_REQUEST['userAction'])) {
  27. $this->userAction();
  28. }
  29. if (!isset($_REQUEST['globalAction']) && !isset($_REQUEST['userAction'])) {
  30. $this->tpl_cp = new genTemplate();
  31. $this->tpl_cp->loadTemplate('cp.main');
  32. $this->selectUserInfo();
  33. }
  34. }
  35. public function gen() {
  36. if (!isset($_REQUEST['globalAction']) && !isset($_REQUEST['userAction'])) {
  37. $this->tpl_cp->set('pictoGrid', $this->genPictoGrid());
  38. $this->tpl_cp->set('infoTime', $this->getInfoTime());
  39. $this->tpl_cp->set('userInfos', $this->genUserInfo());
  40. $this->tpl_cp->set('updatedRubs', $this->getUpdatedRubs());
  41. $this->tpl_cp->set('validatedRubs', $this->getValidatedRubs());
  42. $this->tpl_cp->set('lastCreatedRubs', $this->getLastCreatedRubs());
  43. $this->tpl_cp->set('lastActions', $this->getLastActions());
  44. $this->tpl_cp->set('globalActions', $this->getGlobalActions());
  45. $this->tpl_cp = $this->tpl_cp;
  46. return $this->tpl_cp->gen();
  47. }
  48. }
  49. public function getLastActions() {
  50. $sql = 'SELECT * FROM s_log_action WHERE fk_admin_id = ' . sql($GLOBALS['gs_obj']->adminid) . '
  51. AND log_action_action = "update"
  52. GROUP BY CONCAT(log_action_table,log_action_fk_id)
  53. ORDER BY log_action_time DESC LIMIT 0, 10';
  54. $res = DoSql($sql);
  55. $h = '<ul class="nav nav-list"><li class="nav-header">' . ta('lastActions') . '</li>';
  56. if ($res->NumRows() == 0) {
  57. $h .= '<li><span class="badge">' . ta('lastActions_none') . '</span></li>';
  58. } else {
  59. foreach ($res as $row) {
  60. $h .= '<li><a href="?curTable=' . $row['log_action_table'] . '&curId=' . $row['log_action_fk_id'] . '">
  61. <img src="' . getPicto($row['log_action_table'], '16x16') . '" alt="" /> ' . limit(strip_tags(getTitleFromRow($row['log_action_table'], getRowFromId($row['log_action_table'], $row['log_action_fk_id'])))) . '</a></li>';
  62. }
  63. }
  64. $h .= '</ul>';
  65. return $h;
  66. }
  67. function globalAction() {
  68. global $_Gconfig, $gs_obj;
  69. $action = akev($_REQUEST, 'globalAction');
  70. //ob_start();
  71. if ($action && in_array($action, $_Gconfig['globalActions']) && $gs_obj->can($action)) {
  72. p('<a class="btn" href="?">&laquo; ' . t('retour') . '</a>');
  73. p('<h3>' . t($action) . '</h3>');
  74. p('<div class="well" >');
  75. $action();
  76. p('</div>');
  77. }
  78. //ob_get_contents();
  79. //return ob_get_clean();
  80. return true;
  81. }
  82. function userAction() {
  83. global $_Gconfig, $gs_obj;
  84. $action = akev($_REQUEST, 'userAction');
  85. //ob_start();
  86. if ($gs_obj->can('edit', $action)) {
  87. p('<h3><a href="?">&laquo; ' . t('retour') . '</a></h3><div class="info" >');
  88. p('<h3>' . t($action) . '</h3>');
  89. $action();
  90. p('</div>');
  91. }
  92. //ob_get_contents();
  93. //return ob_get_clean();
  94. return true;
  95. }
  96. function getGlobalActions() {
  97. global $_Gconfig, $gs_obj;
  98. $html = "<div id='list_action' class='list_right' >";
  99. $html .= '<ul class="nav nav-list"><li class="nav-header">' . t('liste_global_actions') . '</li>';
  100. foreach ($_Gconfig['globalActions'] as $action) {
  101. if ($gs_obj->can($action)) {
  102. $i = '';
  103. if (tradExists('picto_' . $action)) {
  104. $i = '<i class="icon-' . t('picto_' . $action) . '"></i>';
  105. }
  106. $html .= '<li><a href="?globalAction=' . $action . '">' . $i . '' . t($action) . '</a></li>';
  107. }
  108. }
  109. $html .= '</ul>';
  110. $html .= '</div>';
  111. return $html;
  112. }
  113. private function genPictoGrid() {
  114. $grid = new genTemplate();
  115. $grid->loadTemplate('cp.picto.grid');
  116. return $grid->gen();
  117. }
  118. private function getInfoTime() {
  119. myLocale(LG);
  120. $date = ucfirst(strftime('%A %d %B %Y'));
  121. //utf8_encode(ucfirst(strftime("%A", strtotime(date('D'))))) .' ' .date('d') .' ' .utf8_encode(ucfirst(strftime("%B", strtotime(date('m'))))) .' ' .date('Y');
  122. return $date;
  123. }
  124. private function selectUserInfo() {
  125. global $_Gconfig;
  126. $this->addUserBlock('user', t('cp_user_info'));
  127. $sql = 'select * from s_admin where admin_id=' . $GLOBALS['gs_obj']->adminid;
  128. $admin = GetSingle($sql);
  129. $lastcx = explode(' ', $_SESSION['last_cx']);
  130. $this->addUserLine('user', t('cp_derniere_connexion'), nicedate($lastcx[0]) . ' à ' . $lastcx[1]);
  131. if (is_array($_Gconfig['ADMIN_LANGUAGES']) && count($_Gconfig['ADMIN_LANGUAGES']) > 1) {
  132. reset($_Gconfig['ADMIN_LANGUAGES']);
  133. foreach ($_Gconfig['ADMIN_LANGUAGES'] as $v) {
  134. $lgs .= '<a href="?lg=' . $v . '"><img src="./img/flags/' . $v . '.gif" alt="' . $v . '"/></a> &nbsp; ';
  135. }
  136. $this->addUserLine('user', t('cp_lg'), $lgs);
  137. }
  138. //$this->UserLines['user'][] = array(t('derniere_connexion')=>nicedate($lastcx[0]) .' à ' .$lastcx[1]);
  139. //$this->addUserLine('user',t('fonction'),$admin['admin_type']);
  140. //$this->UserLines['user'][] = array(t('fonction')=> $admin['admin_type']);
  141. }
  142. private function genUserInfo() {
  143. $tpl = new genTemplate();
  144. $tpl->loadTemplate('cp.userinfo');
  145. $tpl->set('user_name', $GLOBALS['gs_obj']->adminnom);
  146. $html = '';
  147. foreach ($this->UserBlocks as $k => $v) {
  148. $html .= '<p class="titre_onglet">' . $v . '</p>';
  149. $html .= '<table cellspacing=0>';
  150. foreach ($this->UserLines[$k] as $k2 => $v2) {
  151. $html .= '
  152. <tr>
  153. <td>' . $k2 . '</td>
  154. <td>' . $v2 . '</td>
  155. </tr>
  156. ';
  157. }
  158. $html .= '</table>';
  159. }
  160. $tpl->set('content', $html);
  161. return $tpl->gen();
  162. }
  163. public function addUserBlock($type, $titre) {
  164. $this->UserBlocks[$type] = $titre;
  165. }
  166. public function addUserLine($type, $nom, $valeur) {
  167. $this->UserLines[$type][$nom] = $valeur;
  168. }
  169. private function getUpdatedRubs() {
  170. $sql = 'select *
  171. from s_rubrique
  172. where rubrique_etat=\'attente\'
  173. and fk_rubrique_id!=0
  174. and fk_rubrique_version_id IS NOT NULL
  175. order by rubrique_date_modif desc';
  176. $res = GetAll($sql);
  177. $tpl = new genTemplate();
  178. $tpl->loadTemplate('cp.updated.rubs');
  179. if (count($res) == 0) {
  180. $temp = '<p class="centre">' . t('cp_no_rubs_updated') . '</p>';
  181. } else {
  182. foreach ($res as $k => $v) {
  183. if ($v['rubrique_titre_fr'] == '')
  184. $v['rubrique_titre_fr'] = '*** Titre en-cours d\'ecriture';
  185. $temp .= '
  186. <tr class="ligne">
  187. <td><a href="?curTable=s_rubrique&curId=' . $v['rubrique_id'] . '">' . $v['rubrique_titre_fr'] . '</a></td>
  188. <td>' . nicedate(substr($v['rubrique_date_modif'], 0, -9)) . '</td>
  189. </tr>';
  190. }
  191. }
  192. $tpl->set('list_rubs', $temp);
  193. return $tpl->gen();
  194. }
  195. private function getValidatedRubs() {
  196. $sql = 'select r1.*, r2.rubrique_date_publi as date_publi
  197. from s_rubrique r1, s_rubrique r2
  198. where r2.rubrique_etat=\'en_ligne\'
  199. and r1.fk_rubrique_version_id=r2.rubrique_id
  200. and r1.fk_rubrique_id!=0
  201. and r1.fk_rubrique_version_id IS NOT NULL
  202. order by r2.rubrique_date_publi desc limit 10';
  203. $res = GetAll($sql);
  204. $tpl = new genTemplate();
  205. $tpl->loadTemplate('cp.validated.rubs');
  206. $temp = '';
  207. foreach ($res as $k => $v) {
  208. if ($GLOBALS['gs_obj']->can('view', 's_rubrique', '', $v['rubrique_id'])) {
  209. if ($v['rubrique_titre_fr'] == '')
  210. $v['rubrique_titre_fr'] = '*** Titre en-cours d\'ecriture';
  211. $temp .= '
  212. <tr class="ligne">
  213. <td><a href="?curTable=s_rubrique&curId=' . $v['rubrique_id'] . '">' . $v['rubrique_titre_fr'] . '</td>
  214. <td>' . nicedate(substr($v['date_publi'], 0, -9)) . '</td>
  215. </tr>';
  216. }
  217. }
  218. if ($temp == '') {
  219. $temp = '<p class="centre">' . t('cp_no_rubs_validated') . '</p>';
  220. }
  221. $tpl->set('list_rubs', $temp);
  222. return $tpl->gen();
  223. }
  224. private function getLastCreatedRubs() {
  225. $sql = 'select *
  226. from s_rubrique
  227. where fk_rubrique_id!=0
  228. and rubrique_etat ="redaction"
  229. and fk_rubrique_version_id IS NOT NULL
  230. order by rubrique_date_crea desc LIMIT 15';
  231. $res = GetAll($sql);
  232. $tpl = new genTemplate();
  233. $tpl->loadTemplate('cp.created.rubs');
  234. $temp = '';
  235. foreach ($res as $k => $v) {
  236. if ($v['rubrique_titre_fr'] == '')
  237. $v['rubrique_titre_fr'] = '*** Titre en-cours d\'ecriture';
  238. $temp .= '
  239. <tr class="ligne">
  240. <td><a href="?curTable=s_rubrique&curId=' . $v['rubrique_id'] . '">' . $v['rubrique_titre_fr'] . '</a></td>
  241. <td>' . nicedate(substr($v['rubrique_date_crea'], 0, -9)) . '</td>
  242. </tr>';
  243. }
  244. $tpl->set('list_rubs', $temp);
  245. return $tpl->gen();
  246. }
  247. private function getLastPublishedRub() {
  248. $sql = 'select * from s_rubrique order by rubrique_date_publi desc';
  249. $res = GetSingle($sql);
  250. }
  251. }
  252. ?>