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;
 }
                     }
                     $taskjobstate->changeStatus($taskjobstate->fields['id'], $taskjobstate::SERVER_HAS_SENT_DATA);
                 }
                 // return an empty dictionnary if there are no jobs.
                 if (count($order->jobs) == 0) {
                     $response = "{}";
                 } else {
                     $response = json_encode($order);
                 }
             }
         }
     }
     break;
 case 'getFilePart':
     $DB->close();
     PluginFusioninventoryDeployFilepart::httpSendFile($_GET);
     exit;
     break;
 case 'setStatus':
     $partjob_mapping = array("checking" => __('Checks', 'fusioninventory'), "downloading" => __('Files download', 'fusioninventory'), "prepare" => __('Files preparation', 'fusioninventory'), "processing" => __('Actions', 'fusioninventory'));
     $error = FALSE;
     $params = array('machineid' => $_GET['machineid'], 'uuid' => $_GET['uuid']);
     if (array_key_exists("status", $_GET) && $_GET['status'] == 'ko') {
         $params['code'] = 'ko';
         if (array_key_exists("currentStep", $_GET)) {
             $params['msg'] = $partjob_mapping[$_GET['currentStep']] . ":" . $_GET['msg'];
         } else {
             $params['msg'] = $_GET['msg'];
         }
         $error = TRUE;
     }