|
913 | 913 | $tickettocreate->fk_soc = $mythirdpartyaccount->id; |
914 | 914 | $tickettocreate->socid = $mythirdpartyaccount->id; |
915 | 915 | $tickettocreate->origin_replyto = $replyto; |
916 | | - $tickettocreate->origin_email = $emailfrom; |
| 916 | + $tickettocreate->origin_email = $replyto; |
917 | 917 | $tickettocreate->ip = $ipaddress; |
918 | 918 | if (is_object($tmpcontract)) { |
919 | 919 | $tickettocreate->fk_contract = $tmpcontract->id; |
|
2325 | 2325 |
|
2326 | 2326 | header("Location: ".$backtourl); |
2327 | 2327 | exit; |
| 2328 | +} elseif ($action == 'uninstall') { |
| 2329 | + $error = 0; |
| 2330 | + $sellyoursaasutils = new SellYourSaasUtils($db); |
| 2331 | + $deletedlinecontract = 0; $deletedlinefacturerec = 0; |
| 2332 | + $contractid = GETPOSTINT("instanceid"); |
| 2333 | + $productid = GETPOSTINT("productid"); |
| 2334 | + if ($contractid <= 0) { |
| 2335 | + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Id")), null, 'errors'); |
| 2336 | + header("Location: ".$backtourl); |
| 2337 | + exit; |
| 2338 | + } |
| 2339 | + if ($productid <= 0) { |
| 2340 | + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductId")), null, 'errors'); |
| 2341 | + header("Location: ".$backtourl); |
| 2342 | + exit; |
| 2343 | + } |
| 2344 | + $tmpproduct = new Product($db); |
| 2345 | + $res = $tmpproduct->fetch($productid); |
| 2346 | + if ($res <= 0) { |
| 2347 | + setEventMessages($tmpproduct->error, null, 'errors'); |
| 2348 | + header("Location: ".$backtourl); |
| 2349 | + exit; |
| 2350 | + } |
| 2351 | + if ($tmpproduct->array_options["options_app_or_option"] != "option") { |
| 2352 | + setEventMessages($langs->trans("ServiceCannotBeUninstalled"), null, 'errors'); |
| 2353 | + header("Location: ".$backtourl); |
| 2354 | + exit; |
| 2355 | + } |
| 2356 | + |
| 2357 | + $db->begin(); |
| 2358 | + $tmpcontract = new Contrat($db); |
| 2359 | + $res = $tmpcontract->fetch($contractid); |
| 2360 | + if ($res <= 0) { |
| 2361 | + setEventMessages($tmpcontract->error, null, 'errors'); |
| 2362 | + $error++; |
| 2363 | + } |
| 2364 | + if (!$error) { |
| 2365 | + foreach ($tmpcontract->lines as $key => $line) { |
| 2366 | + // Remove service line(s) from contract |
| 2367 | + if ($line->fk_product == $productid) { |
| 2368 | + $res = $tmpcontract->deleteLine($line->id, $user); |
| 2369 | + if ($res <= 0) { |
| 2370 | + setEventMessages($tmpcontract->error, null, 'errors'); |
| 2371 | + $error++; |
| 2372 | + } else { |
| 2373 | + $deletedlinecontract ++; |
| 2374 | + } |
| 2375 | + } |
| 2376 | + } |
| 2377 | + |
| 2378 | + if (!$error) { |
| 2379 | + // Remove service line(s) from recurring invoice |
| 2380 | + $tmpcontract->fetchObjectLinked(); |
| 2381 | + $arrayfacturerec = array_values($tmpcontract->linkedObjects["facturerec"]); |
| 2382 | + |
| 2383 | + if (count($arrayfacturerec) != 1) { |
| 2384 | + // TODO: Send mail auto to inform admins of multiples faturerec contract |
| 2385 | + $error ++; |
| 2386 | + } else { |
| 2387 | + $facturerec = $arrayfacturerec[0]; |
| 2388 | + foreach ($facturerec->lines as $key => $line) { |
| 2389 | + if ($line->fk_product == $productid) { |
| 2390 | + $res = $line->delete($user); |
| 2391 | + if ($res <= 0) { |
| 2392 | + setEventMessages($line->error, null, 'errors'); |
| 2393 | + $error++; |
| 2394 | + } else { |
| 2395 | + $deletedlinefacturerec ++; |
| 2396 | + } |
| 2397 | + } |
| 2398 | + } |
| 2399 | + } |
| 2400 | + } |
| 2401 | + } |
| 2402 | + |
| 2403 | + // Call to remoteaction to undeploy option |
| 2404 | + if (!$error) { |
| 2405 | + $object = $tmpcontract; |
| 2406 | + $type_db = $conf->db->type; |
| 2407 | + $hostname_db = $object->array_options['options_hostname_db']; |
| 2408 | + $username_db = $object->array_options['options_username_db']; |
| 2409 | + $password_db = $object->array_options['options_password_db']; |
| 2410 | + $database_db = $object->array_options['options_database_db']; |
| 2411 | + $port_db = (!empty($object->array_options['options_port_db']) ? $object->array_options['options_port_db'] : 3306); |
| 2412 | + $prefix_db = (!empty($object->array_options['options_prefix_db']) ? $object->array_options['options_prefix_db'] : 'llx_'); |
| 2413 | + $hostname_os = $object->array_options['options_hostname_os']; |
| 2414 | + $username_os = $object->array_options['options_username_os']; |
| 2415 | + $password_os = $object->array_options['options_password_os']; |
| 2416 | + $username_web = $object->thirdparty->email; |
| 2417 | + $password_web = $object->thirdparty->array_options['options_password']; |
| 2418 | + |
| 2419 | + $tmp = explode('.', $object->ref_customer, 2); |
| 2420 | + $object->instance = $tmp[0]; |
| 2421 | + |
| 2422 | + $object->hostname_db = $hostname_db; |
| 2423 | + $object->username_db = $username_db; |
| 2424 | + $object->password_db = $password_db; |
| 2425 | + $object->database_db = $database_db; |
| 2426 | + $object->port_db = $port_db; |
| 2427 | + $object->prefix_db = $prefix_db; |
| 2428 | + $object->username_os = $username_os; |
| 2429 | + $object->password_os = $password_os; |
| 2430 | + $object->hostname_os = $hostname_os; |
| 2431 | + $object->username_web = $username_web; |
| 2432 | + $object->password_web = $password_web; |
| 2433 | + |
| 2434 | + $result = $sellyoursaasutils->sellyoursaasRemoteAction("undeployoption", $object); |
| 2435 | + if ($result <= 0) { |
| 2436 | + $error++; |
| 2437 | + setEventMessages($sellyoursaasutils->error, $sellyoursaasutils->errors, 'errors'); |
| 2438 | + } |
| 2439 | + } |
| 2440 | + |
| 2441 | + if (!$deletedlinecontract || !$deletedlinefacturerec) { |
| 2442 | + $error ++; |
| 2443 | + setEventMessages("FailedToUninstallOption", null, 'errors'); |
| 2444 | + } |
| 2445 | + |
| 2446 | + if ($error) { |
| 2447 | + $db->rollback(); |
| 2448 | + } else { |
| 2449 | + $db->commit(); |
| 2450 | + setEventMessages($langs->trans("OptionSuccessfullyUninstalled"), null, 'mesgs'); |
| 2451 | + } |
| 2452 | + |
| 2453 | + header('Location: '.$_SERVER["PHP_SELF"].'?mode=instances&tab=resources_'.$object->id); |
| 2454 | + exit(); |
| 2455 | +} elseif ($action == 'install') { |
| 2456 | + $error = 0; |
| 2457 | + $sellyoursaasutils = new SellYourSaasUtils($db); |
| 2458 | + $contractid = GETPOSTINT("instanceid"); |
| 2459 | + $productid = GETPOSTINT("productid"); |
| 2460 | + if ($contractid <= 0) { |
| 2461 | + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Id")), null, 'errors'); |
| 2462 | + header("Location: ".$backtourl); |
| 2463 | + exit; |
| 2464 | + } |
| 2465 | + if ($productid <= 0) { |
| 2466 | + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductId")), null, 'errors'); |
| 2467 | + header("Location: ".$backtourl); |
| 2468 | + exit; |
| 2469 | + } |
| 2470 | + $tmpproduct = new Product($db); |
| 2471 | + $res = $tmpproduct->fetch($productid); |
| 2472 | + if ($res <= 0) { |
| 2473 | + setEventMessages($tmpproduct->error, null, 'errors'); |
| 2474 | + header("Location: ".$backtourl); |
| 2475 | + exit; |
| 2476 | + } |
| 2477 | + if ($tmpproduct->array_options["options_app_or_option"] != "option") { |
| 2478 | + setEventMessages($langs->trans("ServiceCannotBeInstalled"), null, 'errors'); |
| 2479 | + header("Location: ".$backtourl); |
| 2480 | + exit; |
| 2481 | + } |
| 2482 | + |
| 2483 | + $db->begin(); |
| 2484 | + $tmpcontract = new Contrat($db); |
| 2485 | + $res = $tmpcontract->fetch($contractid); |
| 2486 | + if ($res <= 0) { |
| 2487 | + setEventMessages($tmpcontract->error, null, 'errors'); |
| 2488 | + $error++; |
| 2489 | + } |
| 2490 | + if (!$error) { |
| 2491 | + $tmparray = sellyoursaasGetExpirationDate($tmpcontract, 0); |
| 2492 | + $duration_value = $tmparray['duration_value']; |
| 2493 | + $duration_unit = $tmparray['duration_unit']; |
| 2494 | + $date_start = dol_now(); |
| 2495 | + $date_end = dol_time_plus_duree($now, $duration_value, $duration_unit) - 1; |
| 2496 | + // Create service line(s) from contract |
| 2497 | + $idlinecontract = $tmpcontract->addline($tmpproduct->description, $tmpproduct->price, 1, $tmpproduct->tva_tx, $tmpproduct->localtax1_tx, $tmpproduct->localtax2_tx, $productid, 0, $date_start, $date_end); |
| 2498 | + if ($idlinecontract <= 0) { |
| 2499 | + setEventMessages($contract->error, null, 'errors'); |
| 2500 | + $error++; |
| 2501 | + } |
| 2502 | + if (!$error) { |
| 2503 | + $tmpcontract->fetch($contractid); |
| 2504 | + $result = $tmpcontract->active_line($user, $idlinecontract, $date_start, '', 'Activation after option deployment'); |
| 2505 | + if (!$result) { |
| 2506 | + // TODO: Send mail auto to inform admins of error activation line |
| 2507 | + $error ++; |
| 2508 | + } |
| 2509 | + } |
| 2510 | + if (!$error) { |
| 2511 | + // create service line(s) from recurring invoice |
| 2512 | + $tmpcontract->fetchObjectLinked(); |
| 2513 | + $arrayfacturerec = array_values($tmpcontract->linkedObjects["facturerec"]); |
| 2514 | + |
| 2515 | + if (count($arrayfacturerec) != 1) { |
| 2516 | + // TODO: Send mail auto to inform admins of multiples faturerec contract |
| 2517 | + $error ++; |
| 2518 | + } else { |
| 2519 | + $facturerec = $arrayfacturerec[0]; |
| 2520 | + $result = $facturerec->addLine($tmpproduct->description, $tmpproduct->price, 1, $tmpproduct->tva_tx, $tmpproduct->localtax1_tx, $tmpproduct->localtax2_tx, $productid, 0, 'HT', 0, '', 0, 0, -1, 0, '', null, 0, 1, 1); |
| 2521 | + if (!$result) { |
| 2522 | + // TODO: Send mail auto to inform admins of error line creation facturRec |
| 2523 | + $error ++; |
| 2524 | + } |
| 2525 | + } |
| 2526 | + } |
| 2527 | + } |
| 2528 | + |
| 2529 | + // Call to remoteaction to deploy option |
| 2530 | + if (!$error) { |
| 2531 | + $object = $tmpcontract; |
| 2532 | + $type_db = $conf->db->type; |
| 2533 | + $hostname_db = $object->array_options['options_hostname_db']; |
| 2534 | + $username_db = $object->array_options['options_username_db']; |
| 2535 | + $password_db = $object->array_options['options_password_db']; |
| 2536 | + $database_db = $object->array_options['options_database_db']; |
| 2537 | + $port_db = (!empty($object->array_options['options_port_db']) ? $object->array_options['options_port_db'] : 3306); |
| 2538 | + $prefix_db = (!empty($object->array_options['options_prefix_db']) ? $object->array_options['options_prefix_db'] : 'llx_'); |
| 2539 | + $hostname_os = $object->array_options['options_hostname_os']; |
| 2540 | + $username_os = $object->array_options['options_username_os']; |
| 2541 | + $password_os = $object->array_options['options_password_os']; |
| 2542 | + $username_web = $object->thirdparty->email; |
| 2543 | + $password_web = $object->thirdparty->array_options['options_password']; |
| 2544 | + |
| 2545 | + $tmp = explode('.', $object->ref_customer, 2); |
| 2546 | + $object->instance = $tmp[0]; |
| 2547 | + |
| 2548 | + $object->hostname_db = $hostname_db; |
| 2549 | + $object->username_db = $username_db; |
| 2550 | + $object->password_db = $password_db; |
| 2551 | + $object->database_db = $database_db; |
| 2552 | + $object->port_db = $port_db; |
| 2553 | + $object->prefix_db = $prefix_db; |
| 2554 | + $object->username_os = $username_os; |
| 2555 | + $object->password_os = $password_os; |
| 2556 | + $object->hostname_os = $hostname_os; |
| 2557 | + $object->username_web = $username_web; |
| 2558 | + $object->password_web = $password_web; |
| 2559 | + |
| 2560 | + //$object->context["options_websitename"] = $website->ref; |
| 2561 | + $result = $sellyoursaasutils->sellyoursaasRemoteAction("deployoption", $object); // Why "rename" and not "deploycustomurl" ? |
| 2562 | + if ($result <= 0) { |
| 2563 | + $error++; |
| 2564 | + setEventMessages($sellyoursaasutils->error, $sellyoursaasutils->errors, 'errors'); |
| 2565 | + } |
| 2566 | + } |
| 2567 | + |
| 2568 | + if ($error) { |
| 2569 | + $db->rollback(); |
| 2570 | + } else { |
| 2571 | + $db->commit(); |
| 2572 | + setEventMessages($langs->trans("OptionSuccessfullyInstalled"), null, 'mesgs'); |
| 2573 | + } |
| 2574 | + |
| 2575 | + header('Location: '.$_SERVER["PHP_SELF"].'?mode=instances&tab=resources_'.$object->id); |
| 2576 | + exit(); |
2328 | 2577 | } |
2329 | 2578 |
|
2330 | 2579 |
|
2331 | 2580 |
|
| 2581 | + |
2332 | 2582 | /* |
2333 | 2583 | * View |
2334 | 2584 | */ |
|
0 commit comments