Code

Layer menu cleanup
[gosa.git] / gosa-core / include / utils / layer-menu / lib / layersmenu-process.inc.php
1 <?php
2 // PHP Layers Menu 3.2.0-rc (C) 2001-2004 Marco Pratesi - http://www.marcopratesi.it/
4 /**
5 * This file contains the code of the ProcessLayersMenu class.
6 * @package PHPLayersMenu
7 */
9 /**
10 * This is an extension of the "common" class of the PHP Layers Menu library.
11 *
12 * It provides methods useful to process/convert menus data, e.g. to output a menu structure and a DB SQL dump corresponding to already parsed data and hence also to convert a menu structure file to a DB SQL dump and viceversa
13 *
14 * @version 3.2.0-rc
15 * @package PHPLayersMenu
16 */
17 class ProcessLayersMenu extends LayersMenuCommon
18 {
20 /**
21 * The constructor method
22 * @return void
23 */
24 function ProcessLayersMenu()
25 {
26         $this->LayersMenuCommon();
27 }
29 /**
30 * The method to set the dirroot directory
31 * @access public
32 * @return boolean
33 */
34 function setDirroot($dirroot)
35 {
36         return $this->setDirrootCommon($dirroot);
37 }
39 /**
40 * Method to output a menu structure corresponding to items of a menu
41 * @access public
42 * @param string $menu_name the name of the menu for which a menu structure
43 *   has to be returned
44 * @param string $separator the character used in the menu structure format
45 *   to separate fields of each item
46 * @return string
47 */
48 function getMenuStructure(
49         $menu_name = '',        // non consistent default...
50         $separator = '|'
51         )
52 {
53         $menuStructure = '';
54         for ($cnt=$this->_firstItem[$menu_name]; $cnt<=$this->_lastItem[$menu_name]; $cnt++) {  // this counter scans all nodes of the menu
55                 $menuStructure .= str_repeat('.', $this->tree[$cnt]['level']);
56                 $menuStructure .= $separator;
57                 $menuStructure .= $this->tree[$cnt]['text'];
58                 $menuStructure .= $separator;
59                 $menuStructure .= $this->tree[$cnt]['href'];
60                 $menuStructure .= $separator;
61                 $menuStructure .= $this->tree[$cnt]['title'];
62                 $menuStructure .= $separator;
63                 $menuStructure .= $this->tree[$cnt]['icon'];
64                 $menuStructure .= $separator;
65                 $menuStructure .= $this->tree[$cnt]['target'];
66                 $menuStructure .= $separator;
67                 $menuStructure .= $this->tree[$cnt]['expanded'];
68                 $menuStructure .= "\n";
69         }
70         return $menuStructure;
71 }
73 /**
74 * Method to output a DB SQL dump corresponding to items of a menu
75 * @access public
76 * @param string $menu_name the name of the menu for which a DB SQL dump
77 *   has to be returned
78 * @param string $db_type the type of DB to dump for;
79 *   leave it either empty or not specified if you are using PHP < 5,
80 *   as sqlite_escape_string() has been added in PHP 5;
81 *   it has to be specified and set to 'sqlite' only if the dump
82 *   has to be prepared for SQLite; it is not significant if != 'sqlite'
83 * @return string
84 */
85 function getSQLDump(
86         $menu_name = '',        // non consistent default...
87         $db_type = ''
88         )
89 {
90         $SQLDump = '';
91         for ($cnt=$this->_firstItem[$menu_name]; $cnt<=$this->_lastItem[$menu_name]; $cnt++) {  // this counter scans all nodes of the menu
92                 $current_node[$this->tree[$cnt]['level']] = $cnt;
93                 if (!$this->tree[$cnt]['child_of_root_node']) {
94                         $this->tree[$cnt]['father_node'] = $current_node[$this->tree[$cnt]['level']-1];
95                 }
96                 $VALUES = '';
97                 $SQLDump .= 'INSERT INTO ';
98                 $SQLDump .= $this->tableName;
99                 $SQLDump .= ' (';
100                 $SQLDump .= $this->tableFields['id'] . ', ';
101                 $VALUES .= "'" . 10*$cnt . "', ";
102                 $SQLDump .= $this->tableFields['parent_id'] . ', ';
103                 if (isset($this->tree[$cnt]['father_node']) && $this->tree[$cnt]['father_node'] != 0) {
104                         $VALUES .= "'" . 10*$this->tree[$cnt]['father_node'] . "', ";
105                 } else {
106                         $VALUES .= "'1', ";
107                 }
108                 $SQLDump .= $this->tableFields['text'] . ', ';
109                 $foobar = $this->tree[$cnt]['text'];
110                 if ($foobar != '') {
111                         if ($db_type != 'sqlite') {
112                                 $foobar = addslashes($foobar);
113                         } else {
114                                 $foobar = sqlite_escape_string($foobar);
115                         }
116                 }
117                 $VALUES .= "'$foobar', ";
118                 $SQLDump .= $this->tableFields['href'] . ', ';
119                 $VALUES .= "'" . $this->tree[$cnt]['href'] . "', ";
120                 if ($this->tableFields['title'] != "''") {
121                         $SQLDump .= $this->tableFields['title'] . ', ';
122                         $foobar = $this->tree[$cnt]['title'];
123                         if ($foobar != '') {
124                                 if ($db_type != 'sqlite') {
125                                         $foobar = addslashes($foobar);
126                                 } else {
127                                         $foobar = sqlite_escape_string($foobar);
128                                 }
129                         }
130                         $VALUES .= "'$foobar', ";
131                 }
132                 if ($this->tableFields['icon'] != "''") {
133                         $SQLDump .= $this->tableFields['icon'] . ', ';
134                         $VALUES .= "'" . $this->tree[$cnt]['icon'] . "', ";
135                 }
136                 if ($this->tableFields['target'] != "''") {
137                         $SQLDump .= $this->tableFields['target'] . ', ';
138                         $VALUES .= "'" . $this->tree[$cnt]['target'] . "', ";
139                 }
140                 if ($this->tableFields['orderfield'] != "''") {
141                         $SQLDump .= $this->tableFields['orderfield'] . ', ';
142                         $VALUES .= "'" . 10*$cnt . "', ";
143                 }
144                 if ($this->tableFields['expanded'] != "''") {
145                         $SQLDump .= $this->tableFields['expanded'] . ', ';
146                         $this->tree[$cnt]['expanded'] = (int) $this->tree[$cnt]['expanded'];
147                         $VALUES .= "'" . $this->tree[$cnt]['expanded'] . "', ";
148                 }
149                 $SQLDump = substr($SQLDump, 0, -2);
150                 $VALUES = substr($VALUES, 0, -2);
151                 $SQLDump .= ") VALUES ($VALUES);\n";
152         }
153         return $SQLDump;
156 } /* END OF CLASS */
158 ?>