global_functions.php
1.67 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
<?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 sections in the database in an array in format "page: section"
function get_sections()
{
global $db;
$pages = $db->query("SELECT * FROM sections");
$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
{
$current_page = "remove";
}
return $current_page;
}
//function that returns all the sections 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;
}