Esempio n. 1
0
 /**
  * Transfer suppliers for specified tickets or problems
  *
  * @since version 0.84
  *
  * @param $itemtype  itemtype : Problem / Ticket
  * @param $ID        original ticket ID
  * @param $newID     new ticket ID
  **/
 function transferLinkedSuppliers($itemtype, $ID, $newID)
 {
     global $DB;
     switch ($itemtype) {
         case 'Ticket':
             $table = 'glpi_suppliers_tickets';
             $field = 'tickets_id';
             $link = new Supplier_Ticket();
             break;
         case 'Problem':
             $table = 'glpi_problems_suppliers';
             $field = 'problems_id';
             $link = new Problem_Supplier();
             break;
     }
     $query = "SELECT *\n                FROM `{$table}`\n                WHERE `{$field}` = '{$ID}'";
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result) != 0) {
             while ($data = $DB->fetch_assoc($result)) {
                 $input = array();
                 if ($data['suppliers_id'] > 0) {
                     $supplier = new Supplier();
                     if ($supplier->getFromDB($data['suppliers_id'])) {
                         $newID = -1;
                         $query = "SELECT *\n                                 FROM `glpi_suppliers`\n                                 WHERE `entities_id` = '" . $this->to . "'\n                                       AND `name` = '" . addslashes($supplier->fields['name']) . "'";
                         if ($result_search = $DB->query($query)) {
                             if ($DB->numrows($result_search) > 0) {
                                 $newID = $DB->result($result_search, 0, 'id');
                             }
                         }
                         if ($newID < 0) {
                             // 1 - create new item
                             unset($supplier->fields['id']);
                             $input = $supplier->fields;
                             $input['entities_id'] = $this->to;
                             // Not set new entity Do by transferItem
                             unset($supplier->fields);
                             $newID = $supplier->add(toolbox::addslashes_deep($input));
                         }
                         $input2['id'] = $data['id'];
                         $input2[$field] = $ID;
                         $input2['suppliers_id'] = $newID;
                         $link->update($input2);
                     }
                 }
             }
         }
     }
 }
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
* @since version 0.85
*/
if (!defined('GLPI_ROOT')) {
    include '../inc/includes.php';
}
$link = new Problem_Supplier();
Session::checkLoginUser();
Html::popHeader(__('Email followup'), $_SERVER['PHP_SELF']);
if (isset($_POST["update"])) {
    $link->check($_POST["id"], UPDATE);
    $link->update($_POST);
    echo "<script type='text/javascript' >\n";
    echo "window.parent.location.reload();";
    echo "</script>";
} else {
    if (isset($_POST['delete'])) {
        $link->check($_POST['id'], DELETE);
        $link->delete($_POST);
        Event::log($link->fields['problems_id'], "problem", 4, "maintain", sprintf(__('%s deletes an actor'), $_SESSION["glpiname"]));
        Html::redirect($CFG_GLPI["root_doc"] . "/front/problem.form.php?id=" . $link->fields['problems_id']);
    } else {
        if (isset($_GET["id"])) {
            $link->showSupplierNotificationForm($_GET["id"]);
        } else {
            Html::displayErrorAndDie('Lost');
        }
Esempio n. 3
0
 /**
  * Transfer suppliers for specified tickets or problems
  *
  * @since version 0.84
  *
  * @param $itemtype  itemtype : Problem / Ticket
  * @param $ID        original ticket ID
  * @param $newID     new ticket ID
  **/
 function transferLinkedSuppliers($itemtype, $ID, $newID)
 {
     global $DB;
     switch ($itemtype) {
         case 'Ticket':
             $table = 'glpi_suppliers_tickets';
             $field = 'tickets_id';
             $link = new Supplier_Ticket();
             break;
         case 'Problem':
             $table = 'glpi_problems_suppliers';
             $field = 'problems_id';
             $link = new Problem_Supplier();
             break;
     }
     $query = "SELECT *\n                FROM `{$table}`\n                WHERE `{$field}` = '{$ID}'";
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result) != 0) {
             while ($data = $DB->fetch_assoc($result)) {
                 $input = array();
                 if ($data['suppliers_id'] > 0) {
                     $supplier = new Supplier();
                     if ($supplier->getFromDB($data['suppliers_id'])) {
                         $inputcat['entities_id'] = $this->to;
                         $inputcat['name'] = addslashes($supplier->fields['name']);
                         $catid = $supplier->findID($inputcat);
                         if ($catid < 0) {
                             $catid = $supplier->import($inputcat);
                         }
                         $input['id'] = $data['id'];
                         $input[$field] = $ID;
                         $input['suppliers_id'] = $catid;
                         $link->update($input);
                     }
                 }
             }
         }
     }
 }