global_functions.php
4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
/**
* Created by PhpStorm.
* User: aleksandarhristov
* Date: 29.01.15
* Time: 09:54
*/
//function that returns all the pages in the database in an array
function get_pages()
{
global $db;
$pages = $db->query("SELECT * FROM pages");
$db_page_title=array();
$i=0;
while ($row=$pages->fetchArray())
{
$db_page_title[$i] = $row[1];
$i++;
}
return $db_page_title;
}
//function that returns all the page id's in the database in an array
function get_pages_id()
{
global $db;
$i=0;
$query=$db->query("SELECT * FROM pages");
while($row=$query->fetchArray())
{
$pages_id[$i]=$row[0];
$i++;
}
return !empty($pages_id) ? $pages_id : '';
}
//function that returns all the sections in the database in an array in format "page: section"
function get_sections()
{
global $db;
$pages = $db->query("SELECT * FROM sections ORDER BY page_id");
$page_section=array();
$i=0;
while ($row=$pages->fetchArray())
{
$db_section_title = $row[2];
$db_page_id = $row[1];
$db_page_title = $db->querySingle("SELECT title FROM pages WHERE id = '$db_page_id'");
$page_section[$i]=$db_page_title.": ".$db_section_title;
$i++;
}
return $page_section;
}
//function that returns the current page as string; needed in the admin sidebar wrapper template to give the active class and color the active page <li>
function current_page()
{
global $current_page;
if(strpos($current_page, "create") !== false)
{
$current_page = "create";
}
else if(strpos($current_page, "edit") !== false)
{
$current_page = "edit";
}
else if(strpos($current_page, "remove") !== false)
{
$current_page = "remove";
}
else
$current_page = "faq";
return $current_page;
}
//function that returns all the sections titles that belong to a specific page
function page_sections($page)
{
global $db;
$page_id = $db->querySingle("SELECT id FROM pages WHERE title='$page'");
$query = $db->query("SELECT * FROM sections WHERE page_id = '$page_id'");
$sections = array();
$i=0;
while ($row=$query->fetchArray())
{
$sections[$i] = $row[2];
$i++;
}
return $sections;
}
//function that returns section id
function return_section_id($section_title, $page_id)
{
global $db;
$query = $db->query("SELECT * FROM sections WHERE page_id = '$page_id'");
$i=0;
while ($row=$query->fetchArray())
{
if ($row[3]==$section_title)
{
break;
}
}
return $i;
}
function return_real_section_id($page_id, $section_id)
{
global $db;
$query = $db->query("SELECT id FROM sections WHERE page_id = '$page_id'");
$i=1;
while ($row = $query->fetchArray())
{
if ($row['id'] == $section_id)
{
return $i;
}
else
{
$i++;
}
}
}
function return_page_id($page_title)
{
global $db;
$page_id = $db->querySingle("SELECT id FROM pages WHERE title = '$page_title'");
return $page_id;
}
function return_real_page_id($page_id)
{
global $db;
$query = $db->query("SELECT id FROM pages WHERE id = '$page_id'");
$i=1;
while ($row = $query->fetchArray())
{
if ($row['id'] == $page_id)
{
return $i;
}
else
{
$i++;
}
}
}
function return_page_title($page_id)
{
global $db;
$page_title = $db->querySingle("SELECT title FROM pages WHERE id = '$page_id'");
return $page_title;
}
function return_section_title($section_id, $page_id)
{
global $db;
$section_title = $db->querySingle("SELECT title FROM sections WHERE id = '$section_id' AND page_id = '$page_id'");
return $section_title;
}
function main_page($return_this, $current_page)
{
global $db;
$query = $db->query("SELECT * FROM pages WHERE id = '$current_page'");
while($row = $query->fetchArray())
{
$page_id = $row[0];
$page_title = $row[1];
$page_text = $row[2];
$sections = $db->query("SELECT * FROM sections WHERE page_id = '$page_id'");
$i = 0;
while($row1 = $sections->fetchArray())
{
$section_id[$i] = $row1[0];
$section_title[$i] = $row1[2];
$section_text[$i] = $row1[3];
$i++;
}
}
switch($return_this)
{
case "page_id":
return !empty($page_id) ? $page_id : '';
break;
case "page_title":
return !empty($page_title) ? $page_title : '';
break;
case "page_text":
return !empty($page_text) ? $page_text : '';
break;
case "section_id":
return !empty($section_id) ? $section_id : '';
break;
case "section_title":
return !empty($section_title) ? $section_title : '';
break;
case "section_text":
return !empty($section_text) ? $section_text : '';
break;
default:
echo "Error!";
}
}