menu.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Copyright (C) 2010 - 2020
  17. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. /**
  22. * menu class
  23. *
  24. * @method null delete
  25. * @method null toggle
  26. * @method null copy
  27. */
  28. if (!class_exists('menu')) {
  29. class menu {
  30. /**
  31. * declare the variables
  32. */
  33. private $app_name;
  34. private $app_uuid;
  35. private $name;
  36. private $table;
  37. private $toggle_field;
  38. private $toggle_values;
  39. private $description_field;
  40. private $location;
  41. public $menu_uuid;
  42. public $menu_language;
  43. public $text;
  44. /**
  45. * called when the object is created
  46. */
  47. public function __construct() {
  48. //assign the variables
  49. $this->app_name = 'menus';
  50. $this->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
  51. $this->location = 'menus.php';
  52. }
  53. /**
  54. * called when there are no references to a particular object
  55. * unset the variables used in the class
  56. */
  57. public function __destruct() {
  58. foreach ($this as $key => $value) {
  59. unset($this->$key);
  60. }
  61. }
  62. /**
  63. * delete rows from the database
  64. */
  65. public function delete($records) {
  66. //assign the variables
  67. $this->name = 'menu';
  68. $this->table = 'menus';
  69. if (permission_exists($this->name.'_delete')) {
  70. //add multi-lingual support
  71. $language = new text;
  72. $text = $language->get();
  73. //validate the token
  74. $token = new token;
  75. if (!$token->validate($_SERVER['PHP_SELF'])) {
  76. message::add($text['message-invalid_token'],'negative');
  77. header('Location: '.$this->location);
  78. exit;
  79. }
  80. //delete multiple records
  81. if (is_array($records) && @sizeof($records) != 0) {
  82. //build the delete array
  83. $x = 0;
  84. foreach ($records as $record) {
  85. if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
  86. //remove menu languages
  87. $array['menu_languages'][$x][$this->name.'_uuid'] = $record['uuid'];
  88. //remove menu item groups
  89. $array['menu_item_groups'][$x][$this->name.'_uuid'] = $record['uuid'];
  90. //remove menu items
  91. $array['menu_items'][$x][$this->name.'_uuid'] = $record['uuid'];
  92. //build array to remove the menu
  93. $array[$this->table][$x][$this->name.'_uuid'] = $record['uuid'];
  94. //increment
  95. $x++;
  96. }
  97. }
  98. //delete the checked rows
  99. if (is_array($array) && @sizeof($array) != 0) {
  100. //grant temporary permissions
  101. $p = new permissions;
  102. $p->add('menu_item_delete', 'temp');
  103. $p->add('menu_item_group_delete', 'temp');
  104. $p->add('menu_language_delete', 'temp');
  105. //execute delete
  106. $database = new database;
  107. $database->app_name = $this->app_name;
  108. $database->app_uuid = $this->app_uuid;
  109. $database->delete($array);
  110. unset($array);
  111. //revoke temporary permissions
  112. $p->delete('menu_item_delete', 'temp');
  113. $p->delete('menu_item_group_delete', 'temp');
  114. $p->delete('menu_language_delete', 'temp');
  115. //set message
  116. message::add($text['message-delete']);
  117. }
  118. unset($records);
  119. }
  120. }
  121. }
  122. public function delete_items($records) {
  123. //assign the variables
  124. $this->name = 'menu_item';
  125. $this->table = 'menu_items';
  126. if (permission_exists($this->name.'_delete')) {
  127. //add multi-lingual support
  128. $language = new text;
  129. $text = $language->get();
  130. //validate the token
  131. $token = new token;
  132. if (!$token->validate('/core/menu/menu_item_list.php')) {
  133. message::add($text['message-invalid_token'],'negative');
  134. header('Location: '.$this->location);
  135. exit;
  136. }
  137. //delete multiple records
  138. if (is_array($records) && @sizeof($records) != 0) {
  139. //build the delete array
  140. $x = 0;
  141. foreach ($records as $record) {
  142. if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
  143. //build array
  144. $uuids[] = "'".$record['uuid']."'";
  145. //remove menu languages
  146. $array['menu_languages'][$x][$this->name.'_uuid'] = $record['uuid'];
  147. //remove menu item groups
  148. $array['menu_item_groups'][$x][$this->name.'_uuid'] = $record['uuid'];
  149. //remove menu items
  150. $array[$this->table][$x][$this->name.'_uuid'] = $record['uuid'];
  151. //increment
  152. $x++;
  153. }
  154. }
  155. //include child menu items
  156. if (is_array($uuids) && @sizeof($uuids) != 0) {
  157. $sql = "select menu_item_uuid as uuid from v_".$this->table." ";
  158. $sql .= "where menu_item_parent_uuid in (".implode(', ', $uuids).") ";
  159. $database = new database;
  160. $rows = $database->select($sql, $parameters, 'all');
  161. if (is_array($rows) && @sizeof($rows) != 0) {
  162. foreach ($rows as $row) {
  163. //remove menu languages
  164. $array['menu_languages'][$x][$this->name.'_uuid'] = $row['uuid'];
  165. //remove menu item groups
  166. $array['menu_item_groups'][$x][$this->name.'_uuid'] = $row['uuid'];
  167. //remove menu items
  168. $array[$this->table][$x][$this->name.'_uuid'] = $row['uuid'];
  169. //increment
  170. $x++;
  171. }
  172. }
  173. }
  174. //delete the checked rows
  175. if (is_array($array) && @sizeof($array) != 0) {
  176. //grant temporary permissions
  177. $p = new permissions;
  178. $p->add('menu_language_delete', 'temp');
  179. $p->add('menu_item_group_delete', 'temp');
  180. //execute delete
  181. $database = new database;
  182. $database->app_name = $this->app_name;
  183. $database->app_uuid = $this->app_uuid;
  184. $database->delete($array);
  185. unset($array);
  186. //revoke temporary permissions
  187. $p->delete('menu_language_delete', 'temp');
  188. $p->delete('menu_item_group_delete', 'temp');
  189. //set message
  190. message::add($text['message-delete']);
  191. }
  192. unset($records);
  193. }
  194. }
  195. }
  196. /**
  197. * toggle a field between two values
  198. */
  199. public function toggle_items($records) {
  200. //assign the variables
  201. $this->name = 'menu_item';
  202. $this->table = 'menu_items';
  203. $this->toggle_field = 'menu_item_protected';
  204. $this->toggle_values = ['true','false'];
  205. if (permission_exists($this->name.'_edit')) {
  206. //add multi-lingual support
  207. $language = new text;
  208. $text = $language->get();
  209. //validate the token
  210. $token = new token;
  211. if (!$token->validate('/core/menu/menu_item_list.php')) {
  212. message::add($text['message-invalid_token'],'negative');
  213. header('Location: '.$this->location);
  214. exit;
  215. }
  216. //toggle the checked records
  217. if (is_array($records) && @sizeof($records) != 0) {
  218. //get current toggle state
  219. foreach ($records as $record) {
  220. if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
  221. $uuids[] = "'".$record['uuid']."'";
  222. }
  223. }
  224. if (is_array($uuids) && @sizeof($uuids) != 0) {
  225. $sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
  226. $sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
  227. $database = new database;
  228. $rows = $database->select($sql, $parameters, 'all');
  229. if (is_array($rows) && @sizeof($rows) != 0) {
  230. foreach ($rows as $row) {
  231. $states[$row['uuid']] = $row['toggle'] == '' ? $this->toggle_values[1] : $row['toggle'];
  232. }
  233. }
  234. unset($sql, $parameters, $rows, $row);
  235. }
  236. //build update array
  237. $x = 0;
  238. foreach ($states as $uuid => $state) {
  239. //create the array
  240. $array[$this->table][$x][$this->name.'_uuid'] = $uuid;
  241. $array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
  242. //increment
  243. $x++;
  244. }
  245. //save the changes
  246. if (is_array($array) && @sizeof($array) != 0) {
  247. //save the array
  248. $database = new database;
  249. $database->app_name = $this->app_name;
  250. $database->app_uuid = $this->app_uuid;
  251. $database->save($array);
  252. unset($array);
  253. //set message
  254. message::add($text['message-toggle']);
  255. }
  256. unset($records, $states);
  257. }
  258. }
  259. }
  260. /**
  261. * delete items in the menu that are not protected
  262. */
  263. public function delete_unprotected() {
  264. //remove existing menu languages
  265. $sql = "delete from v_menu_languages ";
  266. $sql .= "where menu_uuid = :menu_uuid ";
  267. $sql .= "and menu_item_uuid in ( ";
  268. $sql .= " select menu_item_uuid ";
  269. $sql .= " from v_menu_items ";
  270. $sql .= " where menu_uuid = :menu_uuid ";
  271. $sql .= " and ( ";
  272. $sql .= " menu_item_protected <> 'true' ";
  273. $sql .= " or menu_item_protected is null ";
  274. $sql .= " ) ";
  275. $sql .= ") ";
  276. $parameters['menu_uuid'] = $this->menu_uuid;
  277. $database = new database;
  278. $database->execute($sql, $parameters);
  279. unset($sql, $parameters);
  280. //remove existing unprotected menu item groups
  281. $sql = "delete from v_menu_item_groups ";
  282. $sql .= "where menu_uuid = :menu_uuid ";
  283. $sql .= "and menu_item_uuid in ( ";
  284. $sql .= " select menu_item_uuid ";
  285. $sql .= " from v_menu_items ";
  286. $sql .= " where menu_uuid = :menu_uuid ";
  287. $sql .= " and ( ";
  288. $sql .= " menu_item_protected <> 'true' ";
  289. $sql .= " or menu_item_protected is null ";
  290. $sql .= " ) ";
  291. $sql .= ") ";
  292. $parameters['menu_uuid'] = $this->menu_uuid;
  293. $database = new database;
  294. $database->execute($sql, $parameters);
  295. unset($sql, $parameters);
  296. //remove existing unprotected menu items
  297. $sql = "delete from v_menu_items ";
  298. $sql .= "where menu_uuid = :menu_uuid ";
  299. $sql .= "and ( ";
  300. $sql .= " menu_item_protected <> 'true' ";
  301. $sql .= " or menu_item_protected is null ";
  302. $sql .= ") ";
  303. $parameters['menu_uuid'] = $this->menu_uuid;
  304. $database = new database;
  305. $database->execute($sql, $parameters);
  306. unset($sql, $parameters);
  307. }
  308. /**
  309. * restore the menu
  310. */
  311. public function restore() {
  312. //get the $apps array from the installed apps from the core and mod directories
  313. $config_list = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/*/*/app_menu.php");
  314. $x = 0;
  315. if (is_array($config_list)) {
  316. foreach ($config_list as $config_path) {
  317. $app_path = dirname($config_path);
  318. $app_path = preg_replace('/\A.*(\/.*\/.*)\z/', '$1', $app_path);
  319. $y = 0;
  320. try {
  321. //echo "[".$x ."] ".$config_path."\n";
  322. include($config_path);
  323. $x++;
  324. }
  325. catch (Exception $e) {
  326. echo 'exception caught: ' . $e->getMessage() . "\n";
  327. exit;
  328. }
  329. }
  330. }
  331. //get the list of languages
  332. $language = new text;
  333. //create a uuid array of the original uuid used as the key and new uuid as the value
  334. if (is_array($apps)) {
  335. $x = 0;
  336. foreach ($apps as $row) {
  337. if (is_array($row['menu'])) {
  338. foreach ($row['menu'] as $menu) {
  339. $uuid_array[$menu['uuid']] = uuid();
  340. }
  341. }
  342. }
  343. }
  344. //if the item uuid is not currently in the db then add it
  345. $sql = "select * from v_menu_items ";
  346. $sql .= "where menu_uuid = :menu_uuid ";
  347. $parameters['menu_uuid'] = $this->menu_uuid;
  348. $database = new database;
  349. $menu_items = $database->select($sql, $parameters, 'all');
  350. //use the app array to restore the default menu
  351. if (is_array($apps)) {
  352. $x = 0;
  353. foreach ($apps as $row) {
  354. if (is_array($row['menu'])) {
  355. foreach ($row['menu'] as $menu) {
  356. //set the variables
  357. if (strlen($menu['title'][$this->menu_language]) > 0) {
  358. $menu_item_title = $menu['title'][$this->menu_language];
  359. }
  360. else {
  361. $menu_item_title = $menu['title']['en-us'];
  362. }
  363. $uuid = $menu['uuid'];
  364. $menu_item_uuid = $uuid_array[$menu['uuid']];
  365. $menu_item_parent_uuid = $uuid_array[$menu['parent_uuid']];
  366. $menu_item_category = $menu['category'];
  367. $menu_item_icon = $menu['icon'];
  368. $menu_item_path = $menu['path'];
  369. $menu_item_order = $menu['order'];
  370. $menu_item_description = $menu['desc'];
  371. //check if the menu item exists and if it does set the row array
  372. $menu_item_exists = false;
  373. foreach ($menu_items as $item) {
  374. if ($item['uuid'] == $menu['uuid']) {
  375. $menu_item_exists = true;
  376. $row = $item;
  377. }
  378. }
  379. //item exists in the database
  380. if ($menu_item_exists) {
  381. //get parent_menu_item_protected
  382. foreach ($menu_items as $item) {
  383. if ($item['uuid'] == $menu['parent_uuid']) {
  384. $parent_menu_item_protected = $item['menu_item_protected'];
  385. }
  386. }
  387. //parent is not protected so the parent uuid needs to be updated
  388. if (is_uuid($menu_item_parent_uuid) && $menu_item_parent_uuid != $row['menu_item_parent_uuid'] && $parent_menu_item_protected != 'true') {
  389. $array['menu_items'][$x]['menu_item_uuid'] = $row['menu_item_uuid'];
  390. $array['menu_items'][$x]['menu_item_parent_uuid'] = $menu_item_parent_uuid;
  391. $x++;
  392. }
  393. }
  394. //item does not exist in the database
  395. if (!$menu_item_exists) {
  396. if ($menu_item_uuid != $menu_item_parent_uuid) {
  397. $array['menu_items'][$x]['menu_item_uuid'] = $menu_item_uuid;
  398. $array['menu_items'][$x]['menu_uuid'] = $this->menu_uuid;
  399. $array['menu_items'][$x]['uuid'] = $uuid;
  400. $array['menu_items'][$x]['menu_item_title'] = $menu_item_title;
  401. $array['menu_items'][$x]['menu_item_link'] = $menu_item_path;
  402. $array['menu_items'][$x]['menu_item_category'] = $menu_item_category;
  403. $array['menu_items'][$x]['menu_item_icon'] = $menu_item_icon;
  404. if (strlen($menu_item_order) > 0) {
  405. $array['menu_items'][$x]['menu_item_order'] = $menu_item_order;
  406. }
  407. if (is_uuid($menu_item_parent_uuid)) {
  408. $array['menu_items'][$x]['menu_item_parent_uuid'] = $menu_item_parent_uuid;
  409. }
  410. $array['menu_items'][$x]['menu_item_description'] = $menu_item_description;
  411. $x++;
  412. }
  413. }
  414. unset($field, $parameters, $num_rows);
  415. //set the menu languages
  416. if (!$menu_item_exists && is_array($language->languages)) {
  417. foreach ($language->languages as $menu_language) {
  418. //set the menu item title
  419. $menu_item_title = $menu["title"][$menu_language];
  420. if (strlen($menu_item_title) == 0) {
  421. $menu_item_title = $menu["title"]['en-us'];
  422. }
  423. //build insert array
  424. $array['menu_languages'][$x]['menu_language_uuid'] = uuid();
  425. $array['menu_languages'][$x]['menu_item_uuid'] = $menu_item_uuid;
  426. $array['menu_languages'][$x]['menu_uuid'] = $this->menu_uuid;
  427. $array['menu_languages'][$x]['menu_language'] = $menu_language;
  428. $array['menu_languages'][$x]['menu_item_title'] = $menu_item_title;
  429. $x++;
  430. }
  431. }
  432. }
  433. }
  434. }
  435. if (is_array($array) && @sizeof($array) != 0) {
  436. //grant temporary permissions
  437. $p = new permissions;
  438. $p->add('menu_item_add', 'temp');
  439. $p->add('menu_language_add', 'temp');
  440. //execute insert
  441. $database = new database;
  442. $database->app_name = 'menu';
  443. $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
  444. $database->save($array);
  445. unset($array);
  446. //revoke temporary permissions
  447. $p->delete('menu_item_add', 'temp');
  448. $p->delete('menu_language_add', 'temp');
  449. }
  450. }
  451. //make sure the default user groups exist
  452. $group = new groups;
  453. $group->defaults();
  454. //get default global group_uuids
  455. $sql = "select group_uuid, group_name from v_groups ";
  456. $sql .= "where domain_uuid is null ";
  457. $database = new database;
  458. $result = $database->select($sql, null, 'all');
  459. if (is_array($result) && @sizeof($result) != 0) {
  460. foreach ($result as $row) {
  461. $group_uuids[$row['group_name']] = $row['group_uuid'];
  462. }
  463. }
  464. unset($sql, $result, $row);
  465. //if there are no groups listed in v_menu_item_groups under menu_item_uuid then add the default groups
  466. if (is_array($apps)) {
  467. $x = 0;
  468. foreach($apps as $app) {
  469. if (is_array($apps)) {
  470. foreach ($app['menu'] as $sub_row) {
  471. if (isset($sub_row['groups'])) {
  472. foreach ($sub_row['groups'] as $group) {
  473. $sql = "select count(*) from v_menu_item_groups ";
  474. $sql .= "where menu_item_uuid = :menu_item_uuid ";
  475. $sql .= "and menu_uuid = :menu_uuid ";
  476. $sql .= "and group_name = :group_name ";
  477. $sql .= "and group_uuid = :group_uuid ";
  478. $parameters['menu_item_uuid'] = $uuid_array[$sub_row['uuid']];
  479. $parameters['menu_uuid'] = $this->menu_uuid;
  480. $parameters['group_name'] = $group;
  481. $parameters['group_uuid'] = $group_uuids[$group];
  482. $database = new database;
  483. $num_rows = $database->select($sql, $parameters, 'column');
  484. if ($num_rows == 0) {
  485. //no menu item groups found, build insert array for defaults
  486. $array['menu_item_groups'][$x]['menu_item_group_uuid'] = uuid();
  487. $array['menu_item_groups'][$x]['menu_uuid'] = $this->menu_uuid;
  488. $array['menu_item_groups'][$x]['menu_item_uuid'] = $uuid_array[$sub_row['uuid']];
  489. $array['menu_item_groups'][$x]['group_name'] = $group;
  490. $array['menu_item_groups'][$x]['group_uuid'] = $group_uuids[$group];
  491. $x++;
  492. }
  493. unset($sql, $parameters, $num_rows);
  494. }
  495. }
  496. }
  497. }
  498. }
  499. if (is_array($array) && @sizeof($array) != 0) {
  500. //grant temporary permissions
  501. $p = new permissions;
  502. $p->add('menu_item_group_add', 'temp');
  503. //execute insert
  504. $database = new database;
  505. $database->app_name = 'menu';
  506. $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
  507. $database->save($array);
  508. unset($array);
  509. //revoke temporary permissions
  510. $p->delete('menu_item_group_add', 'temp');
  511. }
  512. }
  513. }
  514. /**
  515. * create the menu
  516. */
  517. public function build_html($menu_item_level = 0) {
  518. $menu_html_full = '';
  519. $menu_array = $this->menu_array();
  520. if (!isset($_SESSION['groups'])) {
  521. $_SESSION['groups'][0]['group_name'] = 'public';
  522. }
  523. if (is_array($menu_array)) {
  524. foreach($menu_array as $menu_field) {
  525. //set the variables
  526. $menu_item_link = $menu_field['menu_item_link'];
  527. $menu_item_category = $menu_field['menu_item_category'];
  528. $menu_items = $menu_field['menu_items'];
  529. //prepare the protected menus
  530. $menu_item_title = ($menu_field['menu_item_protected'] == "true") ? $menu_field['menu_item_title'] : $menu_field['menu_language_title'];
  531. //prepare the menu_tags according to the category
  532. $menu_tags = '';
  533. switch ($menu_item_category) {
  534. case "internal":
  535. $menu_tags = "href='".PROJECT_PATH.$submenu_item_link."'";
  536. break;
  537. case "external":
  538. if (substr($submenu_item_link, 0,1) == "/") {
  539. $submenu_item_link = PROJECT_PATH.$submenu_item_link;
  540. }
  541. $menu_tags = "href='".$submenu_item_link."' target='_blank'";
  542. break;
  543. case "email":
  544. $menu_tags = "href='mailto:".$submenu_item_link."'";
  545. break;
  546. }
  547. if ($menu_item_level == 0) {
  548. $menu_html = "<ul class='menu_main'>\n";
  549. $menu_html .= "<li>\n";
  550. if (!isset($_SESSION["username"])) {
  551. $_SESSION["username"] = '';
  552. }
  553. if (strlen($_SESSION["username"]) == 0) {
  554. $menu_html .= "<a $menu_tags style='padding: 0px 0px; border-style: none; background: none;'><h2 align='center' style=''>".$menu_item_title."</h2></a>\n";
  555. }
  556. else {
  557. if ($submenu_item_link == "/login.php" || $submenu_item_link == "/users/signup.php") {
  558. //hide login and sign-up when the user is logged in
  559. }
  560. else {
  561. if (strlen($submenu_item_link) == 0) {
  562. $menu_html .= "<h2 align='center' style=''>".$menu_item_title."</h2>\n";
  563. }
  564. else {
  565. $menu_html .= "<a ".$menu_tags." style='padding: 0px 0px; border-style: none; background: none;'><h2 align='center' style=''>".$menu_item_title."</h2></a>\n";
  566. }
  567. }
  568. }
  569. }
  570. if (is_array($menu_field['menu_items']) && count($menu_field['menu_items']) > 0) {
  571. $menu_html .= $this->build_child_html($menu_item_level, $menu_field['menu_items']);
  572. }
  573. if ($menu_item_level == 0) {
  574. $menu_html .= "</li>\n";
  575. $menu_html .= "</ul>\n\n";
  576. }
  577. $menu_html_full .= $menu_html;
  578. } //end for each
  579. }
  580. return $menu_html_full;
  581. }
  582. /**
  583. * create the sub menus
  584. */
  585. private function build_child_html($menu_item_level, $submenu_array) {
  586. $menu_item_level = $menu_item_level+1;
  587. if (count($_SESSION['groups']) == 0) {
  588. $_SESSION['groups'][0]['group_name'] = 'public';
  589. }
  590. if (is_array($submenu_array)) {
  591. //child menu found
  592. $submenu_html = "<ul class='menu_sub'>\n";
  593. foreach($submenu_array as $submenu_field) {
  594. //set the variables
  595. $menu_item_link = $submenu_field['menu_item_link'];
  596. $menu_item_category = $submenu_field['menu_item_category'];
  597. $menu_items = $submenu_field['menu_items'];
  598. //prepare the protected menus
  599. $menu_item_title = ($submenu_field['menu_item_protected'] == "true") ? $submenu_field['menu_item_title'] : $submenu_field['menu_language_title'];
  600. //prepare the menu_tags according to the category
  601. switch ($menu_item_category) {
  602. case "internal":
  603. $menu_tags = "href='".PROJECT_PATH.$menu_item_link."'";
  604. break;
  605. case "external":
  606. if (substr($menu_item_link, 0,1) == "/") {
  607. $menu_item_link = PROJECT_PATH.$menu_item_link;
  608. }
  609. $menu_tags = "href='".$menu_item_link."' target='_blank'";
  610. break;
  611. case "email":
  612. $menu_tags = "href='mailto:".$menu_item_link."'";
  613. break;
  614. }
  615. $submenu_html .= "<li>";
  616. //get sub menu for children
  617. if (is_array($menu_items) && count($menu_items) > 0) {
  618. $str_child_menu = $this->build_child_html($menu_item_level, $menu_items);
  619. }
  620. if (strlen($str_child_menu) > 1) {
  621. $submenu_html .= "<a ".$menu_tags.">".$menu_item_title."</a>";
  622. $submenu_html .= $str_child_menu;
  623. unset($str_child_menu);
  624. }
  625. else {
  626. $submenu_html .= "<a ".$menu_tags.">".$menu_item_title."</a>";
  627. }
  628. $submenu_html .= "</li>\n";
  629. }
  630. unset($submenu_array);
  631. $submenu_html .="</ul>\n";
  632. return $submenu_html;
  633. }
  634. }
  635. /**
  636. * create the menu array
  637. */
  638. public function menu_array($menu_item_level = 0) {
  639. //if there are no groups then set the public group
  640. if (!isset($_SESSION['groups'][0]['group_name'])) {
  641. $_SESSION['groups'][0]['group_name'] = 'public';
  642. }
  643. //get the menu from the database
  644. $sql = "select i.menu_item_link, l.menu_item_title as menu_language_title, ";
  645. $sql .= "i.menu_item_title, i.menu_item_protected, i.menu_item_category, ";
  646. $sql .= "i.menu_item_icon, i.menu_item_uuid, i.menu_item_parent_uuid ";
  647. $sql .= "from v_menu_items as i, v_menu_languages as l ";
  648. $sql .= "where i.menu_item_uuid = l.menu_item_uuid ";
  649. $sql .= "and l.menu_language = :menu_language ";
  650. $sql .= "and l.menu_uuid = :menu_uuid ";
  651. $sql .= "and i.menu_uuid = :menu_uuid ";
  652. $sql .= "and i.menu_item_parent_uuid is null ";
  653. $sql .= "and i.menu_item_uuid in ";
  654. $sql .= "( ";
  655. $sql .= "select menu_item_uuid ";
  656. $sql .= "from v_menu_item_groups ";
  657. $sql .= "where menu_uuid = :menu_uuid ";
  658. $x = 0;
  659. foreach($_SESSION['groups'] as $row) {
  660. $sql_where_or[] = "group_name = :group_name_".$x;
  661. $parameters['group_name_'.$x] = $row['group_name'];
  662. $x++;
  663. }
  664. if (is_array($sql_where_or) && @sizeof($sql_where_or) != 0) {
  665. $sql .= "and ( ";
  666. $sql .= implode(' or ', $sql_where_or);
  667. $sql .= ") ";
  668. }
  669. $sql .= "and menu_item_uuid is not null ";
  670. $sql .= ") ";
  671. $sql .= "order by i.menu_item_order asc ";
  672. $parameters['menu_language'] = $_SESSION['domain']['language']['code'];
  673. $parameters['menu_uuid'] = $this->menu_uuid;
  674. $database = new database;
  675. $result = $database->select($sql, $parameters, 'all');
  676. unset($sql, $parameters);
  677. //save the menu into an array
  678. $x = 0;
  679. $a = Array();
  680. if (is_array($result) && @sizeof($result) != 0) {
  681. foreach($result as $row) {
  682. //add the row to the array
  683. $a[$x] = $row;
  684. //add the sub menus to the array
  685. $menu_item_level = 0;
  686. if (strlen($row['menu_item_uuid']) > 0) {
  687. $a[$x]['menu_items'] = $this->menu_child_array($menu_item_level, $row['menu_item_uuid']);
  688. }
  689. //increment the row number
  690. $x++;
  691. }
  692. }
  693. unset($result, $row);
  694. //return the array
  695. return $a;
  696. }
  697. /**
  698. * create the sub menus
  699. */
  700. private function menu_child_array($menu_item_level, $menu_item_uuid) {
  701. //set the level
  702. $menu_item_level = $menu_item_level + 1;
  703. //if there are no groups then set the public group
  704. if (!isset($_SESSION['groups'][0]['group_name'])) {
  705. $_SESSION['groups'][0]['group_name'] = 'public';
  706. }
  707. //get the child menu from the database
  708. $sql = "select i.menu_item_link, l.menu_item_title as menu_language_title, i.menu_item_title, i.menu_item_protected, i.menu_item_category, i.menu_item_icon, i.menu_item_uuid, i.menu_item_parent_uuid ";
  709. $sql .= "from v_menu_items as i, v_menu_languages as l ";
  710. $sql .= "where i.menu_item_uuid = l.menu_item_uuid ";
  711. $sql .= "and l.menu_language = :menu_language ";
  712. $sql .= "and l.menu_uuid = :menu_uuid ";
  713. $sql .= "and i.menu_uuid = :menu_uuid ";
  714. $sql .= "and i.menu_item_parent_uuid = :menu_item_parent_uuid ";
  715. $sql .= "and i.menu_item_uuid in ";
  716. $sql .= "( ";
  717. $sql .= "select menu_item_uuid ";
  718. $sql .= "from v_menu_item_groups ";
  719. $sql .= "where menu_uuid = :menu_uuid ";
  720. $x = 0;
  721. foreach($_SESSION['groups'] as $row) {
  722. $sql_where_or[] = "group_name = :group_name_".$x;
  723. $parameters['group_name_'.$x] = $row['group_name'];
  724. $x++;
  725. }
  726. if (is_array($sql_where_or) && @sizeof($sql_where_or) != 0) {
  727. $sql .= "and ( ";
  728. $sql .= implode(' or ', $sql_where_or);
  729. $sql .= ") ";
  730. }
  731. $sql .= ") ";
  732. $sql .= "order by l.menu_item_title, i.menu_item_order asc ";
  733. $parameters['menu_language'] = $_SESSION['domain']['language']['code'];
  734. $parameters['menu_uuid'] = $this->menu_uuid;
  735. $parameters['menu_item_parent_uuid'] = $menu_item_uuid;
  736. $database = new database;
  737. $sub_result = $database->select($sql, $parameters, 'all');
  738. unset($sql, $parameters);
  739. //save the child menu into an array
  740. $x = 0;
  741. $a = Array();
  742. if (is_array($sub_result) && @sizeof($sub_result) != 0) {
  743. foreach($sub_result as $row) {
  744. //set the variables
  745. $menu_item_link = $row['menu_item_link'];
  746. $menu_item_category = $row['menu_item_category'];
  747. $menu_item_icon = $row['menu_item_icon'];
  748. $menu_item_uuid = $row['menu_item_uuid'];
  749. $menu_item_parent_uuid = $row['menu_item_parent_uuid'];
  750. //add the row to the array
  751. $a[$x] = $row;
  752. //prepare the protected menus
  753. if ($row['menu_item_protected'] == "true") {
  754. $a[$x]['menu_item_title'] = $row['menu_item_title'];
  755. }
  756. else {
  757. $a[$x]['menu_item_title'] = $row['menu_language_title'];
  758. }
  759. //get sub menu for children
  760. if (strlen($menu_item_uuid) > 0) {
  761. $a[$x]['menu_items'] = $this->menu_child_array($menu_item_level, $menu_item_uuid);
  762. }
  763. //increment the row
  764. $x++;
  765. }
  766. }
  767. unset($sub_result, $row);
  768. //return the array
  769. return $a;
  770. }
  771. /**
  772. * add the default menu when no menu exists
  773. */
  774. public function menu_default() {
  775. //set the default menu_uuid
  776. $this->menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286';
  777. //check to see if any menu exists
  778. $sql = "select count(*) as count from v_menus ";
  779. $sql .= "where menu_uuid = :menu_uuid ";
  780. $parameters['menu_uuid'] = $this->menu_uuid;
  781. $database = new database;
  782. $num_rows = $database->select($sql, $parameters, 'column');
  783. if ($num_rows == 0) {
  784. //built insert array
  785. $array['menus'][0]['menu_uuid'] = $this->menu_uuid;
  786. $array['menus'][0]['menu_name'] = 'default';
  787. $array['menus'][0]['menu_language'] = 'en-us';
  788. $array['menus'][0]['menu_description'] = 'Default Menu';
  789. //grant temporary permissions
  790. $p = new permissions;
  791. $p->add('menu_add', 'temp');
  792. //execute insert
  793. $database = new database;
  794. $database->app_name = 'menu';
  795. $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
  796. $database->save($array);
  797. unset($array);
  798. //revoke temporary permissions
  799. $p->delete('menu_add', 'temp');
  800. //add the menu items
  801. $this->restore();
  802. }
  803. unset($sql, $parameters, $result, $row);
  804. }
  805. /**
  806. * build the fixed, static or inline horizontal menu html
  807. */
  808. public function menu_horizontal($menu_array) {
  809. //determine menu behavior
  810. $menu_style = $_SESSION['theme']['menu_style']['text'] != '' ? $_SESSION['theme']['menu_style']['text'] : 'fixed';
  811. switch ($menu_style) {
  812. case 'inline':
  813. $menu_type = 'default';
  814. $menu_width = 'calc(100% - 20px)';
  815. $menu_brand = false;
  816. $menu_corners = null;
  817. break;
  818. case 'static':
  819. $menu_type = 'static-top';
  820. $menu_width = 'calc(100% - 40px)';
  821. $menu_brand = true;
  822. $menu_corners = "style='-webkit-border-radius: 0 0 4px 4px; -moz-border-radius: 0 0 4px 4px; border-radius: 0 0 4px 4px;'";
  823. break;
  824. case 'fixed':
  825. default:
  826. $menu_type = 'fixed-'.($_SESSION['theme']['menu_position']['text'] != '' ? $_SESSION['theme']['menu_position']['text'] : 'top');
  827. if (!http_user_agent('mobile')) {
  828. $menu_width = $_SESSION['theme']['menu_width_fixed']['text'] != '' ? $_SESSION['theme']['menu_width_fixed']['text'] : 'calc(90% - 20px)';
  829. }
  830. $menu_brand = true;
  831. $menu_corners = null;
  832. }
  833. //begin navbar code
  834. $html = "<nav class='navbar navbar-expand-sm ".$menu_type."' ".$menu_corners.">\n";
  835. $html .= " <div class='container-fluid' style='width: ".$menu_width."; padding: 0;'>\n";
  836. $html .= " <div class='navbar-brand'>\n";
  837. if ($menu_brand) {
  838. //define menu brand mark
  839. $menu_brand_text = ($_SESSION['theme']['menu_brand_text']['text'] != '') ? escape($_SESSION['theme']['menu_brand_text']['text']) : "FusionPBX";
  840. switch ($_SESSION['theme']['menu_brand_type']['text']) {
  841. case 'text':
  842. $html .= " <a class='navbar-brand-text' href='".PROJECT_PATH."/'>".$menu_brand_text."</a>\n";
  843. break;
  844. case 'image_text':
  845. $menu_brand_image = ($_SESSION['theme']['menu_brand_image']['text'] != '') ? escape($_SESSION['theme']['menu_brand_image']['text']) : PROJECT_PATH."/themes/default/images/logo.png";
  846. $html .= " <a href='".PROJECT_PATH."/'>";
  847. $html .= " <img id='menu_brand_image' class='navbar-logo' src='".$menu_brand_image."' title=\"".escape($menu_brand_text)."\">";
  848. if ($_SESSION['theme']['menu_brand_image_hover']['text'] != '') {
  849. $html .= "<img id='menu_brand_image_hover' class='navbar-logo' style='display: none;' src='".$_SESSION['theme']['menu_brand_image_hover']['text']."' title=\"".escape($menu_brand_text)."\">";
  850. }
  851. $html .= "</a>\n";
  852. $html .= " <a class='navbar-brand-text' href='".PROJECT_PATH."/'>".$menu_brand_text."</a>\n";
  853. break;
  854. case 'none':
  855. break;
  856. case 'image':
  857. default:
  858. $menu_brand_image = ($_SESSION['theme']['menu_brand_image']['text'] != '') ? escape($_SESSION['theme']['menu_brand_image']['text']) : PROJECT_PATH."/themes/default/images/logo.png";
  859. $html .= " <a href='".PROJECT_PATH."/'>";
  860. $html .= " <img id='menu_brand_image' class='navbar-logo' src='".$menu_brand_image."' title=\"".escape($menu_brand_text)."\">";
  861. if (isset($_SESSION['theme']['menu_brand_image_hover']['text']) && $_SESSION['theme']['menu_brand_image_hover']['text'] != '') {
  862. $html .= "<img id='menu_brand_image_hover' class='navbar-logo' style='display: none;' src='".$_SESSION['theme']['menu_brand_image_hover']['text']."' title=\"".escape($menu_brand_text)."\">";
  863. }
  864. $html .= "</a>\n";
  865. $html .= " <a style='margin: 0;'></a>\n";
  866. }
  867. }
  868. $html .= " </div>\n";
  869. $html .= " <button type='button' class='navbar-toggler' data-toggle='collapse' data-target='#main_navbar' aria-expanded='false' aria-controls='main_navbar' aria-label='Toggle Menu'>\n";
  870. $html .= " <span class='fas fa-bars'></span>\n";
  871. $html .= " </button>\n";
  872. $html .= " <div class='collapse navbar-collapse' id='main_navbar'>\n";
  873. $html .= " <ul class='navbar-nav'>\n";
  874. if (is_array($menu_array) && sizeof($menu_array) != 0) {
  875. foreach ($menu_array as $index_main => $menu_parent) {
  876. $mod_li = "nav-item";
  877. $mod_a_1 = "";
  878. $submenu = false;
  879. if (is_array($menu_parent['menu_items']) && sizeof($menu_parent['menu_items']) > 0) {
  880. $mod_li = "nav-item dropdown ";
  881. $mod_a_1 = "data-toggle='dropdown' ";
  882. $submenu = true;
  883. }
  884. $mod_a_2 = ($menu_parent['menu_item_link'] != '' && !$submenu) ? $menu_parent['menu_item_link'] : '#';
  885. $mod_a_3 = ($menu_parent['menu_item_category'] == 'external') ? "target='_blank' " : null;
  886. if (isset($_SESSION['theme']['menu_main_icons']['boolean']) && $_SESSION['theme']['menu_main_icons']['boolean'] == 'true') {
  887. if ($menu_parent['menu_item_icon'] != '' && substr_count($menu_parent['menu_item_icon'], 'fa-') > 0) {
  888. $menu_main_icon = "<span class='fas ".$menu_parent['menu_item_icon']."' title=\"".escape($menu_parent['menu_language_title'])."\"></span>\n";
  889. }
  890. else {
  891. $menu_main_icon = null;
  892. }
  893. $menu_main_item = "<span class='d-sm-none d-md-none d-lg-inline' style='margin-left: 5px;'>".$menu_parent['menu_language_title']."</span>\n";
  894. }
  895. else {
  896. $menu_main_item = $menu_parent['menu_language_title'];
  897. }
  898. $html .= " <li class='".$mod_li."'>\n";
  899. $html .= " <a class='nav-link' ".$mod_a_1." href='".$mod_a_2."' ".$mod_a_3.">\n";
  900. $html .= " ".$menu_main_icon.$menu_main_item;
  901. $html .= " </a>\n";
  902. if ($submenu) {
  903. $html .= " <ul class='dropdown-menu'>\n";
  904. foreach ($menu_parent['menu_items'] as $index_sub => $menu_sub) {
  905. $mod_a_2 = $menu_sub['menu_item_link'];
  906. if ($mod_a_2 == '') {
  907. $mod_a_2 = '#';
  908. }
  909. $mod_a_3 = ($menu_sub['menu_item_category'] == 'external') ? "target='_blank' " : null;
  910. $menu_sub_icon = null;
  911. if ($_SESSION['theme']['menu_sub_icons']['boolean'] != 'false') {
  912. if ($menu_sub['menu_item_icon'] != '' && substr_count($menu_sub['menu_item_icon'], 'fa-') > 0) {
  913. $menu_sub_icon = "<span class='fas ".escape($menu_sub['menu_item_icon'])."'></span>";
  914. }
  915. else {
  916. $menu_sub_icon = null;
  917. }
  918. }
  919. $html .= " <li class='nav-item'><a class='nav-link' href='".$mod_a_2."' ".$mod_a_3.">".($_SESSION['theme']['menu_sub_icons'] ? "<span class='fas fa-bar d-inline-block d-sm-none float-left' style='margin: 4px 10px 0 25px;'></span>" : null).escape($menu_sub['menu_language_title']).$menu_sub_icon."</a></li>\n";
  920. }
  921. $html .= " </ul>\n";
  922. }
  923. $html .= " </li>\n";
  924. }
  925. }
  926. $html .= " </ul>\n";
  927. $html .= " <ul class='navbar-nav ml-auto'>\n";
  928. //domain name/selector
  929. if (isset($_SESSION['username']) && $_SESSION['username'] != '' && permission_exists('domain_select') && count($_SESSION['domains']) > 1 && $_SESSION['theme']['domain_visible']['text'] == 'true') {
  930. $html .= " <li class='nav-item'>\n";
  931. $html .= " <a class='nav-link domain_selector_domain' href='#' title='".$this->text['theme-label-open_selector']."'>".escape($_SESSION['domain_name'])."</a>";
  932. $html .= " </li>\n";
  933. }
  934. //logout icon
  935. if (isset($_SESSION['username']) && $_SESSION['username'] != '' && $_SESSION['theme']['logout_icon_visible']['text'] == "true") {
  936. $username_full = $_SESSION['username'].((count($_SESSION['domains']) > 1) ? "@".$_SESSION["user_context"] : null);
  937. $html .= " <li class='nav-item'>\n";
  938. $html .= " <a class='nav-link logout_icon' href='#' title=\"".$this->text['theme-label-logout']."\" onclick=\"modal_open('modal-logout','btn_logout');\"><span class='fas fa-sign-out-alt'></span></a>";
  939. $html .= " </li>\n";
  940. unset($username_full);
  941. }
  942. $html .= " </ul>\n";
  943. $html .= " </div>\n";
  944. $html .= " </div>\n";
  945. $html .= "</nav>\n";
  946. //modal for logout icon (above)
  947. if (isset($_SESSION['username']) && $_SESSION['username'] != '' && $_SESSION['theme']['logout_icon_visible']['text'] == "true") {
  948. $html .= modal::create(['id'=>'modal-logout','type'=>'general','message'=>$this->text['theme-confirm-logout'],'actions'=>button::create(['type'=>'button','label'=>$this->text['theme-label-logout'],'icon'=>'sign-out-alt','id'=>'btn_logout','style'=>'float: right; margin-left: 15px;','collapse'=>'never','link'=>PROJECT_PATH.'/logout.php','onclick'=>"modal_close();"])]);
  949. }
  950. return $html;
  951. unset($html);
  952. }
  953. /**
  954. * build the vertical side menu html
  955. */
  956. public function menu_vertical($menu_array) {
  957. //menu brand image and/or text
  958. if ($_SESSION['theme']['menu_brand_type']['text'] == 'none') {
  959. $html = " <div style='height: 75px;'>\n";
  960. $html .= "<a class='menu_side_item_main menu_side_contract' onclick='menu_side_contract();' style='display: none;'><i class='fas fa-chevron-left' style='z-index: 99800; padding-left: 3px;'></i></a>";
  961. $html .= "<a class='menu_side_item_main menu_side_expand' onclick='menu_side_expand();'><i class='fas fa-bars' style='z-index: 99800; padding-left: 3px;'></i></a>";
  962. $html .= "</div>\n";
  963. }
  964. else {
  965. $html = " <div id='menu_side_brand_container'>\n";
  966. //menu toggle buttons
  967. if ($_SESSION['theme']['menu_brand_type']['text'] != 'none') {
  968. $html .= " <div style='float: right; margin-right: -20px; margin-top: -20px;'>\n";
  969. $html .= " <a class='menu_side_item_main menu_side_contract' onclick='menu_side_contract();' style='display: none;'><i class='fas fa-chevron-left'></i></a>\n";
  970. $html .= " </div>\n";
  971. }
  972. //show the menu brand image and/or text
  973. $menu_brand_image_contracted = $_SESSION['theme']['menu_side_brand_image_contracted']['text'] != '' ? $_SESSION['theme']['menu_side_brand_image_contracted']['text'] : PROJECT_PATH."/themes/default/images/logo_side_contracted.png";
  974. $menu_brand_image_expanded = $_SESSION['theme']['menu_side_brand_image_expanded']['text'] != '' ? $_SESSION['theme']['menu_side_brand_image_expanded']['text'] : PROJECT_PATH."/themes/default/images/logo_side_expanded.png";
  975. $menu_brand_text = ($_SESSION['theme']['menu_brand_text']['text'] != '') ? escape($_SESSION['theme']['menu_brand_text']['text']) : "FusionPBX";
  976. if ($_SESSION['theme']['menu_brand_type']['text'] == 'image' || $_SESSION['theme']['menu_brand_type']['text'] == '') {
  977. $html .= " <a href='".PROJECT_PATH."/' style='text-decoration: none;'>";
  978. $html .= "<img id='menu_brand_image_contracted' style='width: 20px; margin-left: -2px; margin-top: -5px;' src='".escape($menu_brand_image_contracted)."' title=\"".escape($menu_brand_text)."\">";
  979. $html .= "<img id='menu_brand_image_expanded' style='display: none;' src='".escape($menu_brand_image_expanded)."' title=\"".escape($menu_brand_text)."\">";
  980. $html .= "</a>\n";
  981. }
  982. else if ($_SESSION['theme']['menu_brand_type']['text'] == 'image_text') {
  983. $html .= " <a href='".PROJECT_PATH."/' style='text-decoration: none;'>";
  984. $html .= "<img id='menu_brand_image_contracted' style='width: 20px; margin-left: -2px; margin-top: -5px;' src='".escape($menu_brand_image_contracted)."' title=\"".escape($menu_brand_text)."\">";
  985. $html .= "<span class='menu_brand_text' style='display: none;'>".$menu_brand_text."</span>";
  986. $html .= "</a>\n";
  987. }
  988. else if ($_SESSION['theme']['menu_brand_type']['text'] == 'text') {
  989. $html .= " <a class='menu_brand_text' style='display: none;' href='".PROJECT_PATH."/'>".$menu_brand_text."</a>\n";
  990. }
  991. $html .= " </div>\n";
  992. }
  993. //main menu items
  994. if (is_array($menu_array) && sizeof($menu_array) != 0) {
  995. foreach ($menu_array as $menu_index_main => $menu_item_main) {
  996. $menu_target = ($menu_item_main['menu_item_category'] == 'external') ? '_blank' : '';
  997. $html .= " <a class='menu_side_item_main' ".($menu_item_main['menu_item_link'] != '' ? "href='".$menu_item_main['menu_item_link']."' target='".$menu_target."'" : "onclick=\"menu_side_expand(); $('#sub_".$menu_item_main['menu_item_uuid']."').slideToggle(180, function() { if (!$(this).is(':hidden')) { $('.menu_side_sub').not($(this)).slideUp(180); } });\"")." title=\"".$menu_item_main['menu_language_title']."\">";
  998. if ($menu_item_main['menu_item_icon'] != '') {
  999. $html .= "<i class='fas ".$menu_item_main['menu_item_icon']." fa-fw' style='z-index: 99800; margin-right: 8px;'></i>";
  1000. }
  1001. $html .= "<span class='menu_side_item_title' style='display: none;'>".$menu_item_main['menu_language_title']."</span>";
  1002. $html .= "</a>\n";
  1003. //sub menu items
  1004. if (is_array($menu_item_main['menu_items']) && sizeof($menu_item_main['menu_items']) != 0) {
  1005. $html .= " <div id='sub_".$menu_item_main['menu_item_uuid']."' class='menu_side_sub' style='display: none;'>\n";
  1006. foreach ($menu_item_main['menu_items'] as $menu_index_sub => $menu_item_sub) {
  1007. $html .= " <a class='menu_side_item_sub' ".($menu_item_sub['menu_item_category'] == 'external' ? "target='_blank'" : null)." href='".$menu_item_sub['menu_item_link']."'>";
  1008. $html .= "<span class='menu_side_item_title' style='display: none;'>".$menu_item_sub['menu_language_title']."</span>";
  1009. $html .= "</a>\n";
  1010. }
  1011. $html .= " </div>\n";
  1012. }
  1013. }
  1014. $html .= " <div style='height: 100px;'></div>\n";
  1015. }
  1016. $html .= "</div>\n";
  1017. $html .= "<div id='content_container' style='padding: 0; width: calc(100% - ".(is_numeric($_SESSION['theme']['menu_side_width_contracted']['text']) ? $_SESSION['theme']['menu_side_width_contracted']['text'] : '55')."px); float: right; padding-top: 0px; text-align: center;'>\n";
  1018. $html .= " <div id='content_header'>\n";
  1019. //header: left
  1020. $html .= "<div class='float-left'>\n";
  1021. $html .= "</div>\n";
  1022. //header: right
  1023. $html .= "<span class='float-right' style='white-space: nowrap;'>";
  1024. //current user
  1025. $html .= "<span style='display: inline-block; padding-right: 20px; font-size: 85%;'>\n";
  1026. $html .= "<strong>".$this->text['theme-label-user']."</strong>: ";
  1027. $html .= "<a href='".PROJECT_PATH."/core/users/user_edit.php?id=user'>".$_SESSION['username']."</a>";
  1028. $html .= "</span>\n";
  1029. //domain name/selector (sm+)
  1030. if (isset($_SESSION['username']) && $_SESSION['username'] != '' && permission_exists('domain_select') && count($_SESSION['domains']) > 1 && $_SESSION['theme']['domain_visible']['text'] == 'true') {
  1031. $html .= "<span style='display: inline-block; padding-right: 10px; font-size: 85%;'>\n";
  1032. $html .= "<strong>".$this->text['theme-label-domain']."</strong>: ";
  1033. $html .= "<a href='#' id='header_domain_selector_domain' title='".$this->text['theme-label-open_selector']."'>".escape($_SESSION['domain_name'])."</a>";
  1034. $html .= "</span>\n";
  1035. }
  1036. //logout icon
  1037. if (isset($_SESSION['username']) && $_SESSION['username'] != '' && $_SESSION['theme']['logout_icon_visible']['text'] == "true") {
  1038. $html .= "<a id='header_logout_icon' href='#' title=\"".$this->text['theme-label-logout']."\" onclick=\"modal_open('modal-logout','btn_logout');\"><span class='fas fa-sign-out-alt'></span></a>";
  1039. }
  1040. $html .= "</span>";
  1041. $html .= " </div>\n";
  1042. //modal for logout icon (above)
  1043. if (isset($_SESSION['username']) && $_SESSION['username'] != '' && $_SESSION['theme']['logout_icon_visible']['text'] == "true") {
  1044. $html .= modal::create(['id'=>'modal-logout','type'=>'general','message'=>$this->text['theme-confirm-logout'],'actions'=>button::create(['type'=>'button','label'=>$this->text['theme-label-logout'],'icon'=>'sign-out-alt','id'=>'btn_logout','style'=>'float: right; margin-left: 15px;','collapse'=>'never','link'=>PROJECT_PATH.'/logout.php','onclick'=>"modal_close();"])]);
  1045. }
  1046. return $html;
  1047. unset($html);
  1048. }
  1049. }
  1050. }
  1051. ?>