public function package_clone($new_name = '')
 {
     if ($this->getField('id') < 0) {
         return FALSE;
     }
     $_SESSION['tmp_clone_package'] = TRUE;
     //duplicate package
     $package_oldId = $this->getField('id');
     if ($new_name == "") {
         $new_name = $this->getField('name');
     }
     $params = $this->fields;
     unset($params['id']);
     $params['name'] = $new_name;
     $new_package = new PluginFusioninventoryDeployPackage();
     $package_newId = $new_package->add($params);
     //duplicate orders
     $order_obj = new PluginFusioninventoryDeployOrder();
     $orders = $order_obj->find("plugin_fusioninventory_deploypackages_id = '" . $package_oldId . "'");
     foreach ($orders as $order_oldId => $order) {
         //create new order for this new package
         $order_param = array('type' => $order['type'], 'create_date' => date("Y-m-d H:i:s"), 'plugin_fusioninventory_deploypackages_id' => $package_newId);
         $order_newId = $order_obj->add($order_param);
         unset($order_param);
         //duplicate checks
         $check_obj = new PluginFusioninventoryDeployCheck();
         $checks = $check_obj->find("plugin_fusioninventory_deployorders_id = '" . $order_oldId . "'");
         foreach ($checks as $check) {
             //create new check for this new order
             unset($check['id']);
             $check['plugin_fusioninventory_deployorders_id'] = $order_newId;
             $check_obj->add($check);
         }
         //duplicate files
         $file_obj = new PluginFusioninventoryDeployFile();
         $files = $file_obj->find("plugin_fusioninventory_deployorders_id = '" . $order_oldId . "'");
         foreach ($files as $file) {
             //create new file for this new order
             unset($file['id']);
             $file['plugin_fusioninventory_deployorders_id'] = $order_newId;
             $file_newId = $file_obj->add($file);
             //duplicate fileparts
             $filepart_obj = new PluginFusioninventoryDeployFilepart();
             $fileparts = $filepart_obj->find("plugin_fusioninventory_deployfiles_id = '" . $order_oldId . "'");
             foreach ($fileparts as $filepart) {
                 //create new filepart for this new file
                 unset($filepart['id']);
                 $filepart['plugin_fusioninventory_deployorders_id'] = $order_newId;
                 $filepart['plugin_fusioninventory_deployfiles_id'] = $file_newId;
                 $filepart_obj->add($filepart);
             }
         }
         //duplicate actions
         $action_obj = new PluginFusioninventoryDeployAction();
         $actions = $action_obj->find("plugin_fusioninventory_deployorders_id = '" . $order_oldId . "'");
         foreach ($actions as $action) {
             //duplicate actions subitem
             $action_subitem_obj = new $action['itemtype']();
             $action_subitem_oldId = $action['items_id'];
             $action_subitem_obj->getFromDB($action_subitem_oldId);
             $params_subitem = $action_subitem_obj->fields;
             unset($params_subitem['id']);
             $action_subitem_newId = $action_subitem_obj->add($params_subitem);
             //special case for command, we need to duplicate commandstatus and commandenvvariables
             if ($action['itemtype'] == 'PluginFusioninventoryDeployAction_Command') {
                 $command_oldId = $action_subitem_oldId;
                 $command_newId = $action_subitem_newId;
                 //duplicate commandstatus
                 $commandstatus_obj = new PluginFusioninventoryDeployAction_Commandstatus();
                 $commandstatus = $commandstatus_obj->find("plugin_fusioninventory_deploycommands_id = '" . $command_oldId . "'");
                 foreach ($commandstatus as $commandstate) {
                     //create new commandstatus for this command
                     unset($commandstate['id']);
                     $commandstate['plugin_fusioninventory_deploycommands_id'] = $command_newId;
                     $commandstatus_obj->add($commandstate);
                 }
                 //duplicate commandenvvariables
                 $commandenvvariables_obj = new PluginFusioninventoryDeployAction_Commandenvvariable();
                 $commandenvvariables = $commandenvvariables_obj->find("plugin_fusioninventory_deploycommands_id = '" . $command_oldId . "'");
                 foreach ($commandenvvariables as $commandenvvariable) {
                     //create new commandenvvariable for this command
                     unset($commandenvvariable['id']);
                     $commandenvvariable['plugin_fusioninventory_deploycommands_id'] = $command_newId;
                     $commandenvvariables_obj->add($commandenvvariable);
                 }
             }
             //create new action for this new order
             unset($action['id']);
             $action['plugin_fusioninventory_deployorders_id'] = $order_newId;
             $action['items_id'] = $action_subitem_newId;
             $action_obj->add($action);
         }
     }
     if ($new_package->getName() == NOT_AVAILABLE) {
         $new_package->fields['name'] = $new_package->getTypeName() . " : " . __('ID') . " " . $new_package->fields['id'];
     }
     $display = isset($this->input['_no_message_link']) ? $new_package->getNameID() : $new_package->getLink();
     // Do not display quotes
     Session::addMessageAfterRedirect(__('Item successfully added', 'fusioninventory') . "&nbsp;: " . stripslashes($display));
     unset($_SESSION['tmp_clone_package']);
     //exit;
 }
  @author    David Durieux
  @co-author
  @copyright Copyright (c) 2010-2014 FusionInventory team
  @license   AGPL License 3.0 or (at your option) any later version
             http://www.gnu.org/licenses/agpl-3.0-standalone.html
  @link      http://www.fusioninventory.org/
  @link      http://forge.fusioninventory.org/projects/fusioninventory-for-glpi/
  @since     2010

  ------------------------------------------------------------------------
*/
include "../../../inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkCentralAccess();
if (!isset($_POST['rand']) && !isset($_POST['subtype'])) {
    exit;
}
$rand = $_POST['rand'];
$mode = $_POST['mode'];
switch ($_POST['type']) {
    case 'check':
        PluginFusioninventoryDeployCheck::displayAjaxValues(NULL, $_POST, $rand, $mode);
        break;
    case 'file':
        PluginFusioninventoryDeployFile::displayAjaxValues(NULL, $_POST, $rand, $mode);
        break;
    case 'action':
        PluginFusioninventoryDeployAction::displayAjaxValues(NULL, $_POST, $rand, $mode);
        break;
}
}
if (!isset($_REQUEST['orders_id']) && !isset($_REQUEST['rand']) && !isset($_REQUEST['subtype'])) {
    exit;
}
if (!is_numeric($_REQUEST['orders_id'])) {
    Toolbox::logDebug("Error: orders_id in request is not an integer");
    Toolbox::logDebug(var_dump($_REQUEST['orders_id']));
    exit;
}
$order = new PluginFusioninventoryDeployOrder();
$order->getFromDB($_REQUEST['orders_id']);
//TODO: In the displayForm function, $_REQUEST is somewhat too much for the '$datas' parameter
// I think we could use only $order -- Kevin 'kiniou' Roy
switch ($_REQUEST['subtype']) {
    case 'check':
        PluginFusioninventoryDeployCheck::displayForm($order, $_REQUEST, $_REQUEST['rand'], $_POST['mode']);
        break;
    case 'file':
        PluginFusioninventoryDeployFile::displayForm($order, $_REQUEST, $_REQUEST['rand'], $_POST['mode']);
        break;
    case 'action':
        PluginFusioninventoryDeployAction::displayForm($order, $_REQUEST, $_REQUEST['rand'], $_POST['mode']);
        break;
    case 'package_json_debug':
        if (isset($order->fields['json'])) {
            PluginFusioninventoryDeployPackage::display_json_debug($order);
        } else {
            echo "{}";
        }
        break;
}