1<script type="text/javascript">
2/* fix for ajax-loading tooltips */
3$('body').tooltip({ selector: '[rel=tooltip]' });
4</script>
5
6<?php
7
8/**
9 * Script to display circuits
10 *
11 */
12
13# verify that user is logged in
14$User->check_user_session();
15# perm check
16$User->check_module_permissions ("circuits", 1, true, false);
17
18# filter circuits or fetch print all?
19$circuit_providers = $Tools->fetch_all_objects("circuitProviders", "name");
20
21# strip tags - XSS
22$_GET = $User->strip_input_tags ($_GET);
23
24# get custom fields
25$custom_fields = $Tools->fetch_custom_fields('circuitProviders');
26# get hidden fields */
27$hidden_fields = json_decode($User->settings->hiddenCustomFields, true);
28$hidden_fields = is_array(@$hidden_fields['circuitProviders']) ? $hidden_fields['circuitProviders'] : array();
29
30# title
31print "<h4>"._('List of Circuit providers')."</h4>";
32print "<hr>";
33
34# print link to manage
35print "<div class='btn-group'>";
36	// add
37	if($User->get_module_permissions ("circuits")>2) {
38    print "<a href='' class='btn btn-sm btn-default open_popup' data-script='app/admin/circuits/edit-provider.php' data-class='700' data-action='add' data-providerid='' style='margin-bottom:10px;'><i class='fa fa-plus'></i> "._('Add provider')."</a>";
39	}
40print "</div>";
41
42# table
43print '<table id="circuitManagement" class="table sorted table-striped table-top" data-cookie-id-table="circuit_providers">';
44
45#headers
46print "<thead>";
47print '<tr>';
48print "	<th><span rel='tooltip' data-container='body' title='"._('Sort by Name')."'>"._('Name')."</span></th>";
49print "	<th><span rel='tooltip' data-container='body' title='"._('Sort by Description')."'>"._('Description').'</span></th>';
50print "	<th><span rel='tooltip' data-container='body' title='"._('Sort by Circuits')."'>"._('Circuits').'</span></th>';
51print "	<th><span rel='tooltip' data-container='body' title='"._('Sort by Contact')."'>"._('Contact').'</span></th>';
52if(sizeof(@$custom_fields) > 0) {
53	foreach($custom_fields as $field) {
54		if(!in_array($field['name'], $hidden_fields)) {
55			print "<th class='hidden-sm hidden-xs hidden-md'><span rel='tooltip' data-container='body' title='"._('Sort by')." ".$Tools->print_custom_field_name ($field['name'])."'>".$Tools->print_custom_field_name ($field['name'])."</th>";
56			$colspanCustom++;
57		}
58	}
59}
60print '	<th class="actions"></th>';
61print '</tr>';
62print "</thead>";
63
64// no circuits
65if($circuit_providers===false) {
66	$colspan = 3 + $colspanCustom;
67	print "<tr>";
68	print "	<td colspan='$colspan'>".$Result->show('info', _('No results')."!", false, false, true)."</td>";
69	print "</tr>";
70}
71// result
72else {
73	foreach ($circuit_providers as $provider) {
74		// count items belonging to provider
75		$cnt = $Database->numObjectsFilter("circuits", "provider", $provider->id);
76		//print details
77		print '<tr>'. "\n";
78		print "	<td><strong><a class='btn btn-xs btn-default' href='".create_link($_GET['page'],"circuits","providers",$provider->id)."'>$provider->name</a></strong></td>";
79		print "	<td>$provider->description</td>";
80		print "	<td>$cnt "._("Circuits")."</td>";
81		print " <td>$provider->contact</td>";
82		//custom
83		if(sizeof(@$custom_fields) > 0) {
84			foreach($custom_fields as $field) {
85				if(!in_array($field['name'], $hidden_fields)) {
86					// create html links
87					$provider->{$field['name']} = $User->create_links($provider->{$field['name']}, $field['type']);
88
89					print "<td class='hidden-sm hidden-xs hidden-md'>".$provider->{$field['name']}."</td>";
90				}
91			}
92		}
93
94		// actions
95        print "<td class='actions'>";
96        $links = [];
97        $links[] = ["type"=>"header", "text"=>"View"];
98        $links[] = ["type"=>"link", "text"=>"Show provider", "href"=>create_link($_GET['page'], "circuits","providers",$provider->id), "icon"=>"eye", "visible"=>"dropdown"];
99        $links[] = ["type"=>"divider"];
100        if($User->get_module_permissions ("circuits")>1) {
101            $links[] = ["type"=>"header", "text"=>"Manage provider"];
102            $links[] = ["type"=>"link", "text"=>"Edit provider", "href"=>"", "class"=>"open_popup", "dataparams"=>"  data-script='app/admin/circuits/edit-provider.php' data-class='700' data-action='edit' data-providerid='$provider->id'", "icon"=>"pencil"];
103        }
104        if($User->get_module_permissions ("circuits")>2) {
105            $links[] = ["type"=>"link", "text"=>"Delete provider", "href"=>"", "class"=>"open_popup", "dataparams"=>"  data-script='app/admin/circuits/edit-provider.php' data-class='700' data-action='delete' data-providerid='$provider->id'", "icon"=>"times"];
106            $links[] = ["type"=>"divider"];
107        }
108        // print links
109        print $User->print_actions($User->user->compress_actions, $links);
110        print "</td>";
111
112		print '</tr>';
113	}
114}
115
116print '</table>';