Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
524077 1 <?php
T 2
3 /*
4 Copyright (c) 2011, Till Brehm, projektfarm Gmbh
5 Modified 2009, Marius Cramer, pixcept KG
6 All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without modification,
9 are permitted provided that the following conditions are met:
10
11     * Redistributions of source code must retain the above copyright notice,
12       this list of conditions and the following disclaimer.
13     * Redistributions in binary form must reproduce the above copyright notice,
14       this list of conditions and the following disclaimer in the documentation
15       and/or other materials provided with the distribution.
16     * Neither the name of ISPConfig nor the names of its contributors
17       may be used to endorse or promote products derived from this software without
18       specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /******************************************
33 * Begin Form configuration
34 ******************************************/
35
36 $tform_def_file = "form/web_folder_user.tform.php";
37
38 /******************************************
39 * End Form configuration
40 ******************************************/
41
7fe908 42 require_once '../../lib/config.inc.php';
MC 43 require_once '../../lib/app.inc.php';
524077 44
T 45 //* Check permissions for module
46 $app->auth->check_module_permissions('sites');
47
48 // Loading classes
49 $app->uses('tpl,tform,tform_actions,validate_cron');
50 $app->load('tform_actions');
51
52 class page_action extends tform_actions {
7fe908 53
524077 54     function onSubmit() {
T 55         global $app, $conf;
7fe908 56
524077 57         // Get the record of the parent domain
2af58c 58         $folder = $app->db->queryOneRecord("select * FROM web_folder WHERE web_folder_id = ? AND ".$app->tform->getAuthSQL('r'), @$this->dataRecord["web_folder_id"]);
7fe908 59         if(!$folder || $folder['web_folder_id'] != @$this->dataRecord['web_folder_id']) $app->tform->errorMessage .= $app->tform->lng("no_folder_perm");
MC 60
524077 61         // Set a few fixed values
T 62         $this->dataRecord["server_id"] = $folder["server_id"];
f4de70 63         
FT 64         // make sure this folder/user combination does not exist already
65         if($this->id > 0){
2af58c 66             $user = $app->db->queryOneRecord("SELECT * FROM web_folder_user WHERE web_folder_id = ? AND username = ? AND web_folder_user_id != ?", $this->dataRecord['web_folder_id'], $this->dataRecord['username'], $this->id);
f4de70 67         } else {
2af58c 68             $user = $app->db->queryOneRecord("SELECT * FROM web_folder_user WHERE web_folder_id = ? AND username = ?", $this->dataRecord['web_folder_id'], $this->dataRecord['username']);
f4de70 69         }
FT 70         if(is_array($user) && !empty($user)) $app->tform->errorMessage .= $app->tform->lng('error_user_exists_already_txt');
7fe908 71
524077 72         parent::onSubmit();
T 73     }
f4de70 74     
FT 75     function onAfterInsert() {
76         global $app, $conf;
77
2af58c 78         $folder = $app->db->queryOneRecord("SELECT * FROM web_folder WHERE web_folder_id = ?", $this->dataRecord["web_folder_id"]);
f4de70 79
FT 80         // The web folder user entry shall be owned by the same group as the web folder
81         $sys_groupid = $app->functions->intval($folder['sys_groupid']);
82
a6e3ae 83         $sql = "UPDATE web_folder_user SET sys_groupid = ? WHERE web_folder_user_id = ?";
MC 84         $app->db->query($sql, $sys_groupid, $this->id);
f4de70 85     }
FT 86     
87     function onAfterUpdate() {
88         global $app, $conf;
89
90         //* When the web folder has been changed
91         if(isset($this->dataRecord['web_folder_id']) && $this->oldDataRecord['web_folder_id'] != $this->dataRecord['web_folder_id']) {
2af58c 92             $folder = $app->db->queryOneRecord("SELECT * FROM web_folder WHERE web_folder_id = ?", $this->dataRecord["web_folder_id"]);
f4de70 93
FT 94             // The web folder user entry shall be owned by the same group as the web folder
95             $sys_groupid = $app->functions->intval($folder['sys_groupid']);
96
2af58c 97             $sql = "UPDATE web_folder_user SET sys_groupid = ? WHERE web_folder_user_id = ?";
MC 98             $app->db->query($sql, $sys_groupid, $this->id);
f4de70 99         }
FT 100
101     }
7fe908 102
524077 103 }
T 104
105 $page = new page_action;
106 $page->onLoad();
107
7fe908 108 ?>