| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
require '../include/ispcp-lib.php'; |
|---|
| 22 |
|
|---|
| 23 |
check_login(__FILE__); |
|---|
| 24 |
|
|---|
| 25 |
$tpl = new pTemplate(); |
|---|
| 26 |
$tpl->define_dynamic('page', Config::get('RESELLER_TEMPLATE_PATH') . '/hosting_plan_edit.tpl'); |
|---|
| 27 |
$tpl->define_dynamic('page_message', 'page'); |
|---|
| 28 |
$tpl->define_dynamic('logged_from', 'page'); |
|---|
| 29 |
|
|---|
| 30 |
$theme_color = Config::get('USER_INITIAL_THEME'); |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
global $hpid; |
|---|
| 38 |
|
|---|
| 39 |
gen_reseller_mainmenu($tpl, Config::get('RESELLER_TEMPLATE_PATH') . '/main_menu_hosting_plan.tpl'); |
|---|
| 40 |
gen_reseller_menu($tpl, Config::get('RESELLER_TEMPLATE_PATH') . '/menu_hosting_plan.tpl'); |
|---|
| 41 |
|
|---|
| 42 |
gen_logged_from($tpl); |
|---|
| 43 |
|
|---|
| 44 |
$tpl->assign( |
|---|
| 45 |
array( |
|---|
| 46 |
'TR_RESELLER_MAIN_INDEX_PAGE_TITLE' => tr('ispCP - Reseller/Edit hosting plan'), |
|---|
| 47 |
'THEME_COLOR_PATH' => "../themes/$theme_color", |
|---|
| 48 |
'THEME_CHARSET' => tr('encoding'), |
|---|
| 49 |
'ISP_LOGO' => get_logo($_SESSION['user_id']) |
|---|
| 50 |
) |
|---|
| 51 |
); |
|---|
| 52 |
|
|---|
| 53 |
$tpl->assign( |
|---|
| 54 |
array( |
|---|
| 55 |
'TR_HOSTING PLAN PROPS' => tr('Hosting plan properties'), |
|---|
| 56 |
'TR_TEMPLATE_NAME' => tr('Template name'), |
|---|
| 57 |
'TR_MAX_SUBDOMAINS' => tr('Max subdomains<br><i>(-1 disabled, 0 unlimited)</i>'), |
|---|
| 58 |
'TR_MAX_ALIASES' => tr('Max aliases<br><i>(-1 disabled, 0 unlimited)</i>'), |
|---|
| 59 |
'TR_MAX_MAILACCOUNTS' => tr('Mail accounts limit<br><i>(-1 disabled, 0 unlimited)</i>'), |
|---|
| 60 |
'TR_MAX_FTP' => tr('FTP accounts limit<br><i>(-1 disabled, 0 unlimited)</i>'), |
|---|
| 61 |
'TR_MAX_SQL' => tr('SQL databases limit<br><i>(-1 disabled, 0 unlimited)</i>'), |
|---|
| 62 |
'TR_MAX_SQL_USERS' => tr('SQL users limit<br><i>(-1 disabled, 0 unlimited)</i>'), |
|---|
| 63 |
'TR_MAX_TRAFFIC' => tr('Traffic limit [MB]<br><i>(0 unlimited)</i>'), |
|---|
| 64 |
'TR_DISK_LIMIT' => tr('Disk limit [MB]<br><i>(0 unlimited)</i>'), |
|---|
| 65 |
'TR_PHP' => tr('PHP'), |
|---|
| 66 |
'TR_CGI' => tr('CGI / Perl'), |
|---|
| 67 |
'TR_BACKUP_RESTORE' => tr('Backup and restore'), |
|---|
| 68 |
'TR_APACHE_LOGS' => tr('Apache logfiles'), |
|---|
| 69 |
'TR_AWSTATS' => tr('AwStats'), |
|---|
| 70 |
'TR_YES' => tr('yes'), |
|---|
| 71 |
'TR_NO' => tr('no'), |
|---|
| 72 |
'TR_BILLING_PROPS' => tr('Billing Settings'), |
|---|
| 73 |
'TR_PRICE' => tr('Price'), |
|---|
| 74 |
'TR_SETUP_FEE' => tr('Setup fee'), |
|---|
| 75 |
'TR_VALUE' => tr('Currency'), |
|---|
| 76 |
'TR_PAYMENT' => tr('Payment period'), |
|---|
| 77 |
'TR_STATUS' => tr('Available for purchasing'), |
|---|
| 78 |
'TR_TEMPLATE_DESCRIPTON' => tr('Description'), |
|---|
| 79 |
'TR_EXAMPLE' => tr('(e.g. EUR)'), |
|---|
| 80 |
'TR_EDIT_HOSTING_PLAN' => tr('Update plan'), |
|---|
| 81 |
'TR_UPDATE_PLAN' => tr('Update plan') |
|---|
| 82 |
) |
|---|
| 83 |
); |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
if (isset($_POST['uaction']) && ('add_plan' === $_POST['uaction'])) { |
|---|
| 90 |
|
|---|
| 91 |
if (check_data_iscorrect($tpl)) { |
|---|
| 92 |
save_data_to_db(); |
|---|
| 93 |
} else { |
|---|
| 94 |
restore_form($tpl, $sql); |
|---|
| 95 |
} |
|---|
| 96 |
} else { |
|---|
| 97 |
|
|---|
| 98 |
if (isset($_GET['hpid'])) { |
|---|
| 99 |
$hpid = $_GET['hpid']; |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
gen_load_ehp_page($tpl, $sql, $hpid, $_SESSION['user_id']); |
|---|
| 103 |
$tpl->assign('MESSAGE', ""); |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
gen_page_message($tpl); |
|---|
| 107 |
$tpl->parse('PAGE', 'page'); |
|---|
| 108 |
$tpl->prnt(); |
|---|
| 109 |
|
|---|
| 110 |
if (Config::get('DUMP_GUI_DEBUG')) dump_gui_debug(); |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
function restore_form(&$tpl, &$sql){ |
|---|
| 117 |
$tpl->assign( |
|---|
| 118 |
array( |
|---|
| 119 |
'HP_NAME_VALUE' => clean_input($_POST['hp_name']), |
|---|
| 120 |
'HP_DESCRIPTION_VALUE' => clean_input($_POST['hp_description']), |
|---|
| 121 |
'TR_MAX_SUB_LIMITS' => clean_input($_POST['hp_sub']), |
|---|
| 122 |
'TR_MAX_ALS_VALUES' => clean_input($_POST['hp_als']), |
|---|
| 123 |
'HP_MAIL_VALUE' => clean_input($_POST['hp_mail']), |
|---|
| 124 |
'HP_FTP_VALUE' => clean_input($_POST['hp_ftp']), |
|---|
| 125 |
'HP_SQL_DB_VALUE' => clean_input($_POST['hp_sql_db']), |
|---|
| 126 |
'HP_SQL_USER_VALUE' => clean_input($_POST['hp_sql_user']), |
|---|
| 127 |
'HP_TRAFF_VALUE' => clean_input($_POST['hp_traff']), |
|---|
| 128 |
'HP_TRAFF' => clean_input($_POST['hp_traff']), |
|---|
| 129 |
'HP_DISK_VALUE' => clean_input($_POST['hp_disk']), |
|---|
| 130 |
'HP_PRICE' => clean_input($_POST['hp_price']), |
|---|
| 131 |
'HP_SETUPFEE' => clean_input($_POST['hp_setupfee']), |
|---|
| 132 |
'HP_CURRENCY' => clean_input($_POST['hp_currency']), |
|---|
| 133 |
'HP_PAYMENT' => clean_input($_POST['hp_payment']) |
|---|
| 134 |
) |
|---|
| 135 |
); |
|---|
| 136 |
|
|---|
| 137 |
if ('_yes_' === $_POST['php']) { |
|---|
| 138 |
$tpl->assign(array('TR_PHP_YES' => 'checked')); |
|---|
| 139 |
} else |
|---|
| 140 |
$tpl->assign(array('TR_PHP_NO' => 'checked')); |
|---|
| 141 |
if ('_yes_' === $_POST['cgi']) { |
|---|
| 142 |
$tpl->assign(array('TR_CGI_YES' => 'checked')); |
|---|
| 143 |
} else |
|---|
| 144 |
$tpl->assign(array('TR_CGI_NO' => 'checked')); |
|---|
| 145 |
|
|---|
| 146 |
if (clean_input($_POST['status'] == 1)) { |
|---|
| 147 |
$tpl->assign(array('TR_STATUS_YES' => 'checked')); |
|---|
| 148 |
} else |
|---|
| 149 |
$tpl->assign(array('TR_STATUS_NO' => 'checked')); |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
function gen_load_ehp_page(&$tpl, &$sql, $hpid, $admin_id) { |
|---|
| 154 |
$_SESSION['hpid'] = $hpid; |
|---|
| 155 |
|
|---|
| 156 |
if (Config::exists('HOSTING_PLANS_LEVEL') && Config::get('HOSTING_PLANS_LEVEL') === 'admin') { |
|---|
| 157 |
$query = <<<SQL_QUERY |
|---|
| 158 |
select |
|---|
| 159 |
* |
|---|
| 160 |
from |
|---|
| 161 |
hosting_plans |
|---|
| 162 |
where |
|---|
| 163 |
id = ?; |
|---|
| 164 |
SQL_QUERY; |
|---|
| 165 |
$res = exec_query($sql, $query, array($hpid)); |
|---|
| 166 |
$readonly = 'readonly'; |
|---|
| 167 |
$disabled = 'disabled'; |
|---|
| 168 |
$edit_hp = tr('View hosting plan'); |
|---|
| 169 |
$tpl->assign('FORM', ""); |
|---|
| 170 |
} else { |
|---|
| 171 |
$query = <<<SQL_QUERY |
|---|
| 172 |
select |
|---|
| 173 |
* |
|---|
| 174 |
from |
|---|
| 175 |
hosting_plans |
|---|
| 176 |
where |
|---|
| 177 |
reseller_id = ? and id = ?; |
|---|
| 178 |
SQL_QUERY; |
|---|
| 179 |
$res = exec_query($sql, $query, array($admin_id, $hpid)); |
|---|
| 180 |
$readonly = ''; |
|---|
| 181 |
$disabled = ''; |
|---|
| 182 |
$edit_hp = tr('Edit hosting plan'); |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
if ($res->RowCount() !== 1) { |
|---|
| 186 |
header('Location: hosting_plan.php'); |
|---|
| 187 |
die(); |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
$data = $res->FetchRow(); |
|---|
| 191 |
$props = $data['props']; |
|---|
| 192 |
$description = $data['description']; |
|---|
| 193 |
$price = $data['price']; |
|---|
| 194 |
$setup_fee = $data['setup_fee']; |
|---|
| 195 |
$value = $data['value']; |
|---|
| 196 |
$payment = $data['payment']; |
|---|
| 197 |
$status = $data['status']; |
|---|
| 198 |
list($hp_php, $hp_cgi, $hp_sub, $hp_als, $hp_mail, $hp_ftp, $hp_sql_db, $hp_sql_user, $hp_traff, $hp_disk) = explode(";", $props); |
|---|
| 199 |
$hp_name = $data['name']; |
|---|
| 200 |
|
|---|
| 201 |
if ($description == '') |
|---|
| 202 |
$description = ''; |
|---|
| 203 |
|
|---|
| 204 |
if ($payment == '') |
|---|
| 205 |
$payment = ''; |
|---|
| 206 |
|
|---|
| 207 |
if ($value == '') |
|---|
| 208 |
$value = ''; |
|---|
| 209 |
|
|---|
| 210 |
$tpl->assign( |
|---|
| 211 |
array( |
|---|
| 212 |
'HP_NAME_VALUE' => stripslashes($hp_name), |
|---|
| 213 |
'TR_EDIT_HOSTING_PLAN' => $edit_hp, |
|---|
| 214 |
'TR_MAX_SUB_LIMITS' => $hp_sub, |
|---|
| 215 |
'TR_MAX_ALS_VALUES' => $hp_als, |
|---|
| 216 |
'HP_MAIL_VALUE' => $hp_mail, |
|---|
| 217 |
'HP_FTP_VALUE' => $hp_ftp, |
|---|
| 218 |
'HP_SQL_DB_VALUE' => $hp_sql_db, |
|---|
| 219 |
'HP_SQL_USER_VALUE' => $hp_sql_user, |
|---|
| 220 |
'HP_TRAFF_VALUE' => $hp_traff, |
|---|
| 221 |
'HP_DISK_VALUE' => $hp_disk, |
|---|
| 222 |
'HP_DESCRIPTION_VALUE' => stripslashes($description), |
|---|
| 223 |
'HP_PRICE' => $price, |
|---|
| 224 |
'HP_SETUPFEE' => $setup_fee, |
|---|
| 225 |
'HP_CURRENCY' => stripslashes($value), |
|---|
| 226 |
'READONLY' => $readonly, |
|---|
| 227 |
'DISBLED' => $disabled, |
|---|
| 228 |
'HP_PAYMENT' => stripslashes($payment) |
|---|
| 229 |
) |
|---|
| 230 |
); |
|---|
| 231 |
|
|---|
| 232 |
if ('_yes_' === $hp_php) { |
|---|
| 233 |
$tpl->assign(array('TR_PHP_YES' => 'checked')); |
|---|
| 234 |
} else |
|---|
| 235 |
$tpl->assign(array('TR_PHP_NO' => 'checked')); |
|---|
| 236 |
if ('_yes_' === $hp_cgi) { |
|---|
| 237 |
$tpl->assign(array('TR_CGI_YES' => 'checked')); |
|---|
| 238 |
} else |
|---|
| 239 |
$tpl->assign(array('TR_CGI_NO' => 'checked')); |
|---|
| 240 |
|
|---|
| 241 |
if ($status == 1) { |
|---|
| 242 |
$tpl->assign(array('TR_STATUS_YES' => 'checked')); |
|---|
| 243 |
} else |
|---|
| 244 |
$tpl->assign(array('TR_STATUS_NO' => 'checked')); |
|---|
| 245 |
} |
|---|
| 246 |
|
|---|
| 247 |
// Check correction of input data |
|---|
| 248 |
function check_data_iscorrect(&$tpl) { |
|---|
| 249 |
global $hp_name, $hp_php, $hp_cgi; |
|---|
| 250 |
global $hp_sub, $hp_als, $hp_mail; |
|---|
| 251 |
global $hp_ftp, $hp_sql_db, $hp_sql_user; |
|---|
| 252 |
global $hp_traff, $hp_disk; |
|---|
| 253 |
global $hpid; |
|---|
| 254 |
global $price, $setup_fee; |
|---|
| 255 |
|
|---|
| 256 |
$ahp_error = "_off_"; |
|---|
| 257 |
$hp_name = clean_input($_POST['hp_name']); |
|---|
| 258 |
$hp_sub = clean_input($_POST['hp_sub']); |
|---|
| 259 |
$hp_als = clean_input($_POST['hp_als']); |
|---|
| 260 |
$hp_mail = clean_input($_POST['hp_mail']); |
|---|
| 261 |
$hp_ftp = clean_input($_POST['hp_ftp']); |
|---|
| 262 |
$hp_sql_db = clean_input($_POST['hp_sql_db']); |
|---|
| 263 |
$hp_sql_user = clean_input($_POST['hp_sql_user']); |
|---|
| 264 |
$hp_traff = clean_input($_POST['hp_traff']); |
|---|
| 265 |
$hp_disk = clean_input($_POST['hp_disk']); |
|---|
| 266 |
$price = clean_input($_POST['hp_price']); |
|---|
| 267 |
$setup_fee = clean_input($_POST['hp_setupfee']); |
|---|
| 268 |
|
|---|
| 269 |
if (isset($_SESSION['hpid'])) |
|---|
| 270 |
$hpid = $_SESSION['hpid']; |
|---|
| 271 |
else |
|---|
| 272 |
$ahp_error = tr('Undefined reference to data!'); |
|---|
| 273 |
|
|---|
| 274 |
$_SESSION['hpid'] = $hpid; |
|---|
| 275 |
|
|---|
| 276 |
if (isset($_POST['php'])) |
|---|
| 277 |
$hp_php = $_POST['php']; |
|---|
| 278 |
|
|---|
| 279 |
if (isset($_POST['cgi'])) |
|---|
| 280 |
$hp_cgi = $_POST['cgi'];; |
|---|
| 281 |
|
|---|
| 282 |
if (!ispcp_limit_check($hp_sub, -1)) { |
|---|
| 283 |
$ahp_error = tr('Incorrect subdomains limit!'); |
|---|
| 284 |
} else if (!ispcp_limit_check($hp_als, -1)) { |
|---|
| 285 |
$ahp_error = tr('Incorrect aliases limit!'); |
|---|
| 286 |
} else if (!ispcp_limit_check($hp_mail, -1)) { |
|---|
| 287 |
$ahp_error = tr('Incorrect mail accounts limit!'); |
|---|
| 288 |
} else if (!ispcp_limit_check($hp_ftp, -1)) { |
|---|
| 289 |
$ahp_error = tr('Incorrect FTP accounts limit!'); |
|---|
| 290 |
} else if (!ispcp_limit_check($hp_sql_user, -1)) { |
|---|
| 291 |
$ahp_error = tr('Incorrect SQL databases limit!'); |
|---|
| 292 |
} else if (!ispcp_limit_check($hp_sql_db, -1)) { |
|---|
| 293 |
$ahp_error = tr('Incorrect SQL users limit!'); |
|---|
| 294 |
} else if (!ispcp_limit_check($hp_traff, null)) { |
|---|
| 295 |
$ahp_error = tr('Incorrect traffic limit!'); |
|---|
| 296 |
} else if (!ispcp_limit_check($hp_disk, null)) { |
|---|
| 297 |
$ahp_error = tr('Incorrect disk quota limit!'); |
|---|
| 298 |
} else if (!is_numeric($price)) { |
|---|
| 299 |
$ahp_error = tr('Price must be a number!'); |
|---|
| 300 |
} else if (!is_numeric($setup_fee)) { |
|---|
| 301 |
$ahp_error = tr('Setup fee must be a number!'); |
|---|
| 302 |
} |
|---|
| 303 |
|
|---|
| 304 |
if ($ahp_error == '_off_') { |
|---|
| 305 |
$tpl->assign('MESSAGE', ''); |
|---|
| 306 |
return true; |
|---|
| 307 |
} else { |
|---|
| 308 |
set_page_message($ahp_error); |
|---|
| 309 |
return false; |
|---|
| 310 |
} |
|---|
| 311 |
} |
|---|
| 312 |
|
|---|
| 313 |
// Add new host plan to DB |
|---|
| 314 |
function save_data_to_db() { |
|---|
| 315 |
$sql = Database::getInstance(); |
|---|
| 316 |
global $tpl; |
|---|
| 317 |
global $hp_name, $hp_php, $hp_cgi; |
|---|
| 318 |
global $hp_sub, $hp_als, $hp_mail; |
|---|
| 319 |
global $hp_ftp, $hp_sql_db, $hp_sql_user; |
|---|
| 320 |
global $hp_traff, $hp_disk; |
|---|
| 321 |
global $hpid; |
|---|
| 322 |
|
|---|
| 323 |
$err_msg = ""; |
|---|
| 324 |
$description = clean_input($_POST['hp_description']); |
|---|
| 325 |
$price = clean_input($_POST['hp_price']); |
|---|
| 326 |
$setup_fee = clean_input($_POST['hp_setupfee']); |
|---|
| 327 |
$currency = clean_input($_POST['hp_currency']); |
|---|
| 328 |
$payment = clean_input($_POST['hp_payment']); |
|---|
| 329 |
$status = clean_input($_POST['status']); |
|---|
| 330 |
|
|---|
| 331 |
$hp_props = "$hp_php;$hp_cgi;$hp_sub;$hp_als;$hp_mail;$hp_ftp;$hp_sql_db;$hp_sql_user;$hp_traff;$hp_disk;"; |
|---|
| 332 |
|
|---|
| 333 |
$admin_id = $_SESSION['user_id']; |
|---|
| 334 |
|
|---|
| 335 |
if (reseller_limits_check($sql, $err_msg, $admin_id, $hpid, $hp_props)) { |
|---|
| 336 |
|
|---|
| 337 |
if (!empty($err_msg)) { |
|---|
| 338 |
set_page_message($err_msg); |
|---|
| 339 |
restore_form($tpl, $sql); |
|---|
| 340 |
return false; |
|---|
| 341 |
} else { |
|---|
| 342 |
$query = <<<SQL_QUERY |
|---|
| 343 |
update |
|---|
| 344 |
hosting_plans |
|---|
| 345 |
set |
|---|
| 346 |
name = ?, |
|---|
| 347 |
description = ?, |
|---|
| 348 |
props = ?, |
|---|
| 349 |
price = ?, |
|---|
| 350 |
setup_fee = ?, |
|---|
| 351 |
value = ?, |
|---|
| 352 |
payment = ?, |
|---|
| 353 |
status = ? |
|---|
| 354 |
where |
|---|
| 355 |
id = ? |
|---|
| 356 |
SQL_QUERY; |
|---|
| 357 |
$res = exec_query($sql, $query, array($hp_name, $description, $hp_props, $price, |
|---|
| 358 |
$setup_fee, $currency, $payment, $status, $hpid)); |
|---|
| 359 |
|
|---|
| 360 |
$_SESSION['hp_updated'] = '_yes_'; |
|---|
| 361 |
header("Location: hosting_plan.php"); |
|---|
| 362 |
die(); |
|---|
| 363 |
} |
|---|
| 364 |
} |
|---|
| 365 |
else { |
|---|
| 366 |
set_page_message(tr("Hosting plan values exceed reseller maximum values!")); |
|---|
| 367 |
return false; |
|---|
| 368 |
} |
|---|
| 369 |
} |
|---|
| 370 |
die(); |
|---|
| 371 |
|
|---|
| 372 |
?> |
|---|