Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
bbc657 1 <?php
MC 2 /*
3 Copyright (c) 2012, ISPConfig UG
4 Contributors: web wack creations,  http://www.web-wack.at
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
b1a6a5 31 require_once '../../lib/config.inc.php';
MC 32 require_once '../../lib/app.inc.php';
bbc657 33 //require_once('classes/class.base.php'); // for constants
MC 34 $app->load('aps_base');
35
36 // Path to the list definition file
37 $list_def_file = "list/aps_installedpackages.list.php";
38
39 // Check the module permissions
40 $app->auth->check_module_permissions('sites');
b1a6a5 41
bbc657 42 // Load needed classes
MC 43 $app->uses('tpl,tform,listform,listform_actions');
44
45 // Show further information only to admins or resellers
46 if($_SESSION['s']['user']['typ'] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid']))
b1a6a5 47     $app->tpl->setVar('is_noclient', 1);
bbc657 48
MC 49 // Show each user the own packages (if not admin)
50 $client_ext = '';
51 $is_admin = ($_SESSION['s']['user']['typ'] == 'admin') ? true : false;
52 if(!$is_admin)
53 {
2af58c 54     $cid = $app->db->queryOneRecord('SELECT client_id FROM client WHERE username = ?', $_SESSION['s']['user']['username']);
b1a6a5 55     //$client_ext = ' AND aps_instances.customer_id = '.$cid['client_id'];
bbc657 56     $client_ext = ' AND '.$app->tform->getAuthSQL('r', 'aps_instances');
MC 57 }
58 $app->listform_actions->SQLExtWhere = 'aps_instances.package_id = aps_packages.id'.$client_ext;
59 $app->listform_actions->SQLOrderBy = 'ORDER BY package_name';
60
61 // We are using parts of listform_actions because ISPConfig doesn't allow
62 // queries over multiple tables so we construct them ourselves
63 $_SESSION['s']['form']['return_to'] = '';
64
b1a6a5 65 // Load the list template
bbc657 66 $app->listform->loadListDef($list_def_file);
b1a6a5 67 if(!is_file('templates/'.$app->listform->listDef["name"].'_list.htm'))
bbc657 68 {
b1a6a5 69     $app->uses('listform_tpl_generator');
MC 70     $app->listform_tpl_generator->buildHTML($app->listform->listDef);
bbc657 71 }
MC 72 $app->tpl->newTemplate("listpage.tpl.htm");
73 $app->tpl->setInclude('content_tpl', 'templates/'.$app->listform->listDef["name"].'_list.htm');
74
75 // Build the WHERE query for search
76 $sql_where = '';
b1a6a5 77 if($app->listform_actions->SQLExtWhere != '')
MC 78     $sql_where .= ' '.$app->listform_actions->SQLExtWhere.' and';
bbc657 79 $sql_where = $app->listform->getSearchSQL($sql_where);
MC 80 $app->tpl->setVar($app->listform->searchValues);
b1a6a5 81
bbc657 82 // Paging
MC 83 $limit_sql = $app->listform->getPagingSQL($sql_where);
84 $app->tpl->setVar('paging', $app->listform->pagingHTML);
85
86 if(!$is_admin) {
b1a6a5 87     // Our query over multiple tables
MC 88     $query = "SELECT aps_instances.id AS id, aps_instances.package_id AS package_id,
89                  aps_instances.customer_id AS customer_id, client.username AS customer_name,
90                  aps_instances.instance_status AS instance_status, aps_packages.name AS package_name,
91                  aps_packages.version AS package_version, aps_packages.release AS package_release,
92                  aps_packages.package_status AS package_status,
93               CONCAT((SELECT value FROM aps_instances_settings WHERE name='main_domain' AND instance_id = aps_instances.id),
94                  '/', (SELECT value FROM aps_instances_settings WHERE name='main_location' AND instance_id = aps_instances.id))
95                   AS install_location
96           FROM aps_instances, aps_packages, client
bbc657 97           WHERE client.client_id = aps_instances.customer_id AND ".$sql_where." ".$app->listform_actions->SQLOrderBy." ".$limit_sql;
MC 98 } else {
b1a6a5 99     $query = "SELECT aps_instances.id AS id, aps_instances.package_id AS package_id,
bbc657 100                  aps_instances.customer_id AS customer_id, sys_group.name AS customer_name,
b1a6a5 101                  aps_instances.instance_status AS instance_status, aps_packages.name AS package_name,
MC 102                  aps_packages.version AS package_version, aps_packages.release AS package_release,
103                  aps_packages.package_status AS package_status,
104               CONCAT((SELECT value FROM aps_instances_settings WHERE name='main_domain' AND instance_id = aps_instances.id),
105                  '/', (SELECT value FROM aps_instances_settings WHERE name='main_location' AND instance_id = aps_instances.id))
106                   AS install_location
107           FROM aps_instances, aps_packages, sys_group
bbc657 108           WHERE sys_group.client_id = aps_instances.customer_id AND ".$sql_where." ".$app->listform_actions->SQLOrderBy." ".$limit_sql;
MC 109
b1a6a5 110 }
bbc657 111
MC 112 $records = $app->db->queryAllRecords($query);
113 $app->listform_actions->DataRowColor = '#FFFFFF';
114
b1a6a5 115 // Re-form all result entries and add extra entries
bbc657 116 $records_new = '';
b1a6a5 117 if(is_array($records))
bbc657 118 {
b1a6a5 119     $app->listform_actions->idx_key = $app->listform->listDef["table_idx"];
MC 120     foreach($records as $rec)
121     {
122         // Set an abbreviated install location to beware the page layout
123         $ils = '';
124         if(strlen($rec['Install_location']) >= 38) $ils = substr($rec['Install_location'], 0,  35).'...';
125         else $ils = $rec['install_location'];
126         $rec['install_location_short'] = $ils;
127
128         // Of course an instance can only then be removed when it's not already tagged for removal
129         if($rec['instance_status'] != INSTANCE_REMOVE && $rec['instance_status'] != INSTANCE_INSTALL)
130             $rec['delete_possible'] = 'true';
131
132         $records_new[] = $app->listform_actions->prepareDataRow($rec);
133     }
bbc657 134 }
MC 135 $app->tpl->setLoop('records', $records_new);
136
137 $app->listform_actions->onShow();
138 ?>