PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/menus/smartphone/smartphone.lib.php

https://github.com/asterix14/dolibarr
PHP | 178 lines | 112 code | 30 blank | 36 comment | 22 complexity | b76d2d0d4961698ed5b6f64518fa10d6 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
  4. *
  5. * This program 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 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
  17. * or see http://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/menus/smartphone/smartphone.lib.php
  21. * \brief Library for file smartphone menus
  22. */
  23. /**
  24. * Core function to output top menu smartphone
  25. *
  26. * @param $db
  27. * @param $atarget
  28. * @param $type_user 0=Internal,1=External,2=All
  29. * @param $limitmenuto To limit menu to a top or left menu value
  30. */
  31. function print_smartphone_menu($db,$atarget,$type_user,$limitmenuto)
  32. {
  33. require_once(DOL_DOCUMENT_ROOT."/core/class/menubase.class.php");
  34. global $user,$conf,$langs,$dolibarr_main_db_name;
  35. $submenus='';
  36. $tabMenu=array();
  37. $menutop = new Menubase($db,'smartphone','top');
  38. $menuleft = new Menubase($db,'smartphone','left');
  39. $newTabMenu = $menutop->menuTopCharger('', '', $type_user, 'smartphone',$tabMenu);
  40. $numTabMenu = count($newTabMenu);
  41. print_start_menu_array();
  42. for($i=0; $i<$numTabMenu; $i++)
  43. {
  44. if ($newTabMenu[$i]['enabled'] == true)
  45. {
  46. if ($newTabMenu[$i]['right'] == true) // Is allowed
  47. {
  48. // Define url
  49. if (preg_match("/^(http:\/\/|https:\/\/)/i",$newTabMenu[$i]['url']))
  50. {
  51. $url = dol_buildpath($newTabMenu[$i]['url'],1);
  52. $url=preg_replace('/&amp.*/i','',$url);
  53. }
  54. else
  55. {
  56. $menus='';
  57. if ($limitmenuto > 0)
  58. {
  59. $newmenu = new Menu();
  60. $leftmenu = $menuleft->menuLeftCharger($newmenu,$newTabMenu[$i]['mainmenu'],'',($user->societe_id?1:0),'smartphone',$tabMenu);
  61. $menus = $leftmenu->liste;
  62. //var_dump($menus);
  63. }
  64. print_start_menu_entry();
  65. if (is_array($menus) && !empty($menus) && $limitmenuto > 0)
  66. {
  67. $title=$newTabMenu[$i]['titre'];
  68. // To remove & and special chars: $title=dol_string_unaccent(dol_string_nospecial(dol_html_entity_decode($newTabMenu[$i]['titre'],ENT_QUOTES,'UTF-8'),'',array('&')));
  69. print_text_menu_entry($title);
  70. $num = count($menus);
  71. //var_dump($menus);
  72. if ($num > 0) print_start_submenu_array();
  73. for($j=0; $j<$num; $j++)
  74. {
  75. $url=dol_buildpath($menus[$j]['url'],1);
  76. $url=preg_replace('/&amp.*/i','',$url);
  77. if ($menus[$j]['level'] == 0)
  78. {
  79. print_start_menu_entry();
  80. if (empty($menus[$j+1]['level'])) print '<a href="'.$url.'"'.($menus[$j]['atarget']?" target='".$menus[$j]['atarget']."'":($atarget?" target=$atarget":'')).'>';
  81. $title=$menus[$j]['titre'];
  82. // To remove & and special chars: $title=dol_string_unaccent(dol_string_nospecial(dol_html_entity_decode($menus[$j]['titre'],ENT_QUOTES,'UTF-8'),'',array('&')));
  83. print_text_menu_entry($title);
  84. if (empty($menus[$j+1]['level'])) print '</a>';
  85. }
  86. if ($menus[$j]['level'] > 0)
  87. {
  88. if ($menus[$j-1]['level'] == 0) print_start_submenu_array();
  89. print_start_menu_entry();
  90. print '<a href="'.$url.'"'.($menus[$j]['atarget']?" target='".$menus[$j]['atarget']."'":($atarget?" target=$atarget":'')).'>';
  91. $title=$menus[$j]['titre'];
  92. // To remove & and special chars: $title=dol_string_unaccent(dol_string_nospecial(dol_html_entity_decode($menus[$j]['titre'],ENT_QUOTES,'UTF-8'),'',array('&')));
  93. print_text_menu_entry($title);
  94. print '</a>';
  95. print_end_menu_entry();
  96. if (empty($menus[$j+1]['level'])) print_end_menu();
  97. }
  98. if (empty($menus[$j+1]['level'])) print_end_menu_entry();
  99. }
  100. if ($num > 0) print_end_menu();
  101. }
  102. else
  103. {
  104. $url=dol_buildpath($newTabMenu[$i]['url'],1);
  105. $url=preg_replace('/&amp.*/i','',$url);
  106. print '<a href="'.$url.'"'.($newTabMenu[$i]['atarget']?" target='".$newTabMenu[$i]['atarget']."'":($atarget?" target=$atarget":'')).'>';
  107. $title=$newTabMenu[$i]['titre'];
  108. // To remove & and special chars: $title=dol_string_unaccent(dol_string_nospecial(dol_html_entity_decode($newTabMenu[$i]['titre'],ENT_QUOTES,'UTF-8'),'',array('&')));
  109. print_text_menu_entry($title);
  110. print '</a>';
  111. }
  112. print_end_menu_entry();
  113. }
  114. }
  115. }
  116. }
  117. print_end_menu();
  118. print "\n";
  119. }
  120. function print_start_menu_array($theme='c')
  121. {
  122. print '<ul data-role="listview" data-theme="'.$theme.'">';
  123. print "\n";
  124. }
  125. function print_start_submenu_array()
  126. {
  127. print '<ul>';
  128. print "\n";
  129. }
  130. function print_start_menu_entry()
  131. {
  132. print '<li>';
  133. }
  134. function print_text_menu_entry($text)
  135. {
  136. print $text;
  137. }
  138. function print_end_menu_entry()
  139. {
  140. print '</li>';
  141. print "\n";
  142. }
  143. function print_end_menu()
  144. {
  145. print '</ul>';
  146. print "\n";
  147. }
  148. ?>