Beispiel #1
0
along with Resources. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
if (!isset($_GET["withtemplate"])) {
    $_GET["withtemplate"] = "";
}
$resource = new PluginResourcesResource();
$checklist = new PluginResourcesChecklist();
$checklistconfig = new PluginResourcesChecklistconfig();
$employee = new PluginResourcesEmployee();
$choice = new PluginResourcesChoice();
$resource_item = new PluginResourcesResource_Item();
$cat = new PluginResourcesTicketCategory();
$task = new PluginResourcesTask();
/////////////////////////////////resource from helpdesk///////////////////////////////
if (isset($_POST["resend"])) {
    $resource->reSendResourceCreation($_POST);
    $resource->redirectToList();
    //from helpdesk
    //add items needs of a resource
} else {
    if (isset($_POST["addhelpdeskitem"])) {
        if ($_POST['plugin_resources_choiceitems_id'] > 0 && $_POST['plugin_resources_resources_id'] > 0) {
            if ($resource->canCreate()) {
                $choice->addHelpdeskItem($_POST);
            }
        }
Beispiel #2
0
 function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     $resource_item = new PluginResourcesResource_Item();
     switch ($input['action']) {
         case "Transfert":
             if ($input['itemtype'] == 'PluginResourcesResource') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         $this->getFromDB($key);
                         $contracttype = PluginResourcesContractType::transfer($PluginResourcesResource->fields["plugin_resources_contracttypes_id"], $input['entities_id']);
                         if ($contracttype > 0) {
                             $values["id"] = $key;
                             $values["plugin_resources_contracttypes_id"] = $contracttype;
                             $this->update($values);
                         }
                         unset($values);
                         $resourcestate = PluginResourcesResourceState::transfer($PluginResourcesResource->fields["plugin_resources_resourcestates_id"], $input['entities_id']);
                         if ($resourcestate > 0) {
                             $values["id"] = $key;
                             $values["plugin_resources_resourcestates_id"] = $resourcestate;
                             $this->update($values);
                         }
                         unset($values);
                         $department = PluginResourcesDepartment::transfer($PluginResourcesResource->fields["plugin_resources_departments_id"], $input['entities_id']);
                         if ($department > 0) {
                             $values["id"] = $key;
                             $values["plugin_resources_departments_id"] = $department;
                             $this->update($values);
                         }
                         unset($values);
                         $situation = PluginResourcesResourceSituation::transfer($PluginResourcesResource->fields["plugin_resources_resourcesituations_id"], $input['entities_id']);
                         if ($situation > 0) {
                             $values["id"] = $key;
                             $values["plugin_resources_resourcesituations_id"] = $situation;
                             $this->update($values);
                         }
                         unset($values);
                         $contractnature = PluginResourcesContractNature::transfer($PluginResourcesResource->fields["plugin_resources_contractnatures_id"], $input['entities_id']);
                         if ($contractnature > 0) {
                             $values["id"] = $key;
                             $values["plugin_resources_contractnatures_id"] = $contractnature;
                             $this->update($values);
                         }
                         unset($values);
                         $rank = PluginResourcesRank::transfer($PluginResourcesResource->fields["plugin_resources_ranks_id"], $input['entities_id']);
                         if ($rank > 0) {
                             $values["id"] = $key;
                             $values["plugin_resources_ranks_id"] = $rank;
                             $this->update($values);
                         }
                         unset($values);
                         $speciality = PluginResourcesResourceSpeciality::transfer($PluginResourcesResource->fields["plugin_resources_resourcespecialities_id"], $input['entities_id']);
                         if ($speciality > 0) {
                             $values["id"] = $key;
                             $values["plugin_resources_resourcespecialities_id"] = $speciality;
                             $this->update($values);
                         }
                         unset($values);
                         $PluginResourcesTask = new PluginResourcesTask();
                         $restrict = "`plugin_resources_resources_id` = '" . $key . "'";
                         $tasks = getAllDatasFromTable("glpi_plugin_resources_tasks", $restrict);
                         if (!empty($tasks)) {
                             foreach ($tasks as $task) {
                                 $PluginResourcesTask->getFromDB($task["id"]);
                                 $tasktype = PluginResourcesTaskType::transfer($PluginResourcesTask->fields["plugin_resources_tasktypes_id"], $input['entities_id']);
                                 if ($tasktype > 0) {
                                     $values["id"] = $task["id"];
                                     $values["plugin_resources_tasktypes_id"] = $tasktype;
                                     $PluginResourcesTask->update($values);
                                 }
                                 $values["id"] = $task["id"];
                                 $values["entities_id"] = $input['entities_id'];
                                 $PluginResourcesTask->update($values);
                             }
                         }
                         unset($values);
                         $PluginResourcesEmployment = new PluginResourcesEmployment();
                         $restrict = "`plugin_resources_resources_id` = '" . $key . "'";
                         $employments = getAllDatasFromTable("glpi_plugin_resources_employments", $restrict);
                         if (!empty($employments)) {
                             foreach ($employments as $employment) {
                                 $PluginResourcesEmployment->getFromDB($employment["id"]);
                                 $rank = PluginResourcesRank::transfer($PluginResourcesEmployment->fields["plugin_resources_ranks_id"], $input['entities_id']);
                                 if ($rank > 0) {
                                     $values["id"] = $employment["id"];
                                     $values["plugin_resources_ranks_id"] = $rank;
                                     $PluginResourcesEmployment->update($values);
                                 }
                                 $PluginResourcesEmployment->getFromDB($employment["id"]);
                                 $profession = PluginResourcesProfession::transfer($PluginResourcesEmployment->fields["plugin_resources_professions_id"], $input['entities_id']);
                                 if ($profession > 0) {
                                     $values["id"] = $employment["id"];
                                     $values["plugin_resources_professions_id"] = $profession;
                                     $PluginResourcesEmployment->update($values);
                                 }
                                 $values["id"] = $employment["id"];
                                 $values["entities_id"] = $input['entities_id'];
                                 $PluginResourcesEmployment->update($values);
                             }
                         }
                         unset($values);
                         $PluginResourcesEmployee = new PluginResourcesEmployee();
                         $restrict = "`plugin_resources_resources_id` = '" . $key . "'";
                         $employees = getAllDatasFromTable("glpi_plugin_resources_employees", $restrict);
                         if (!empty($employees)) {
                             foreach ($employees as $employee) {
                                 $employer = PluginResourcesEmployer::transfer($employee["plugin_resources_employers_id"], $input['entities_id']);
                                 if ($employer > 0) {
                                     $values["id"] = $employee["id"];
                                     $values["plugin_resources_employers_id"] = $employer;
                                     $PluginResourcesEmployee->update($values);
                                 }
                                 $client = PluginResourcesClient::transfer($employee["plugin_resources_clients_id"], $input['entities_id']);
                                 if ($client > 0) {
                                     $values["id"] = $employee["id"];
                                     $values["plugin_resources_clients_id"] = $client;
                                     $PluginResourcesEmployee->update($values);
                                 }
                             }
                         }
                         unset($values);
                         $query = "UPDATE `glpi_plugin_resources_checklists`\n                        SET `entities_id` = '" . $input['entities_id'] . "'\n                        WHERE `plugin_resources_resources_id` ='{$key}'";
                         $DB->query($query);
                         $values["id"] = $key;
                         $values["entities_id"] = $input['entities_id'];
                         if ($this->update($values)) {
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     }
                 }
             }
             break;
         case "Install":
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     $values = array('plugin_resources_resources_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']);
                     if ($resource_item->add($values)) {
                         $res['ok']++;
                     } else {
                         $res['ko']++;
                     }
                 }
             }
             break;
         case "Desinstall":
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     if ($resource_item->deleteItemByResourcesAndItem($key, $input['item_item'], $input['typeitem'])) {
                         $res['ok']++;
                     } else {
                         $res['ko']++;
                     }
                 }
             }
             break;
         case "Send":
             if ($this->sendEmail($input)) {
                 $res['ok']++;
             } else {
                 $res['ko']++;
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
             break;
     }
     return $res;
 }
Beispiel #3
0
 function showItemFromPlugin($instID, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $PluginResourcesTask = new PluginResourcesTask();
     if ($PluginResourcesTask->getFromDB($instID)) {
         $plugin_resources_resources_id = $PluginResourcesTask->fields["plugin_resources_resources_id"];
         $PluginResourcesResource = new PluginResourcesResource();
         $PluginResourcesResource->getFromDB($plugin_resources_resources_id);
         $canedit = $PluginResourcesResource->can($plugin_resources_resources_id, 'w');
         $query = "SELECT `items_id`, `itemtype` \n               FROM `" . $this->getTable() . "` \n               WHERE `plugin_resources_tasks_id` = '{$instID}' \n               ORDER BY `itemtype` ";
         $result = $DB->query($query);
         $number = $DB->numrows($result);
         echo "<form method='post' name='addtaskitem' action=\"./task.form.php\">";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr>";
         echo "<th colspan='" . ($canedit ? 3 : 2) . "'>" . _n('Associated item', 'Associated items', 2);
         echo "</th></tr>";
         echo "<tr><th>" . _n('Type', 'Types', 2) . "</th>";
         echo "<th>" . __('Name') . "</th>";
         if ($canedit && $this->canCreate() && $withtemplate < 2) {
             echo "<th>&nbsp;</th>";
         }
         echo "</tr>";
         $used = array();
         if ($number != "0") {
             for ($i = 0; $i < $number; $i++) {
                 $type = $DB->result($result, $i, "itemtype");
                 $items_id = $DB->result($result, $i, "items_id");
                 if (!class_exists($type)) {
                     continue;
                 }
                 $item = new $type();
                 if ($item->canView()) {
                     $table = getTableForItemType($type);
                     $query = "SELECT `" . $table . "`.*, `" . $this->getTable() . "`.`id` as items_id \n                        FROM `" . $this->getTable() . "` \n                        INNER JOIN `" . $table . "` ON (`" . $table . "`.`id` = `" . $this->getTable() . "`.`items_id`) \n                        WHERE `" . $this->getTable() . "`.`itemtype` = '" . $type . "' \n                        AND `" . $this->getTable() . "`.`items_id` = '" . $items_id . "' \n                        AND `" . $this->getTable() . "`.`plugin_resources_tasks_id` = '{$instID}' ";
                     $query .= "ORDER BY `" . $table . "`.`name` ";
                     $result_linked = $DB->query($query);
                     if ($DB->numrows($result_linked)) {
                         while ($data = $DB->fetch_assoc($result_linked)) {
                             $ID = "";
                             $itemID = $data["id"];
                             $used[] = $itemID;
                             if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                                 $ID = " (" . $data["id"] . ")";
                             }
                             $itemname = $data["name"];
                             if ($type == 'User') {
                                 $itemname = getUserName($itemID);
                             }
                             $link = Toolbox::getItemTypeFormURL($type);
                             $name = "<a href=\"" . $link . "\">" . $itemname . "{$ID}</a>";
                             echo "<tr class='tab_bg_1'>";
                             echo "<td class='center'>" . $item->getTypeName() . "</td>";
                             echo "<td class='center' " . (isset($data['is_deleted']) && $data['is_deleted'] == '1' ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>";
                             if ($canedit && $this->canCreate() && $withtemplate < 2) {
                                 echo "<td class='center' class='tab_bg_2'>";
                                 Html::showSimpleForm($CFG_GLPI['root_doc'] . '/plugins/resources/front/task.form.php', 'deletetaskitem', _x('button', 'Delete permanently'), array('id' => $data["items_id"]));
                                 echo "</td>";
                             }
                             echo "</tr>";
                         }
                     }
                 }
             }
         }
         if ($canedit && $this->canCreate() && $withtemplate < 2) {
             echo "<tr class='tab_bg_1'><td colspan='2' class='right'>";
             echo "<input type='hidden' name='plugin_resources_tasks_id' value='{$instID}'>";
             $PluginResourcesResource_Item = new PluginResourcesResource_Item();
             $PluginResourcesResource_Item->dropdownItems($plugin_resources_resources_id, $used);
             echo "</td>";
             echo "<td class='center' colspan='2' class='tab_bg_2'>";
             echo "<input type='submit' name='addtaskitem' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
             echo "</td></tr>";
             echo "</table></div>";
         } else {
             echo "</table></div>";
         }
         Html::closeForm();
         echo "<br>";
     }
 }
Beispiel #4
0
function plugin_resources_MassiveActionsProcess($data)
{
    global $DB;
    $nbok = 0;
    $nbnoright = 0;
    $nbko = 0;
    $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
    $messageKo = "";
    $messageOk = "";
    $resourceItem = new PluginResourcesResource_Item();
    switch ($data['action']) {
        case "plugin_resources_add_item":
            foreach ($data["item"] as $key => $val) {
                if ($val == 1) {
                    $input = array('plugin_resources_resources_id' => $data['plugin_resources_resources_id'], 'items_id' => $key, 'itemtype' => $data['itemtype']);
                    if ($resourceItem->can(-1, 'w', $input)) {
                        if ($resourceItem->add($input)) {
                            $res['ok']++;
                        } else {
                            $res['ko']++;
                        }
                    } else {
                        $res['noright']++;
                    }
                }
            }
            break;
        case "plugin_resources_generate_resources":
            if (sizeof($data['item']) > 0) {
                foreach ($data['item'] as $userId => $val) {
                    $user = new User();
                    $user->getFromDB($userId);
                    $resource = new PluginResourcesResource();
                    $query = "WHERE name='" . $user->fields['realname'] . "' AND firstname='" . $user->fields['firstname'] . "' ";
                    $resource->getFromDBByQuery($query);
                    if (!isset($resource->fields['id']) || $resource->fields['id'] <= 0) {
                        $resource->fields['entities_id'] = $_SESSION['glpiactive_entity'];
                        $resource->fields['name'] = isset($user->fields['realname']) ? $user->fields['realname'] : '';
                        $resource->fields['firstname'] = isset($user->fields['firstname']) ? $user->fields['firstname'] : '';
                        $resource->fields['plugin_resources_contracttypes_id'] = $data['plugin_resources_contracttypes_id'];
                        $resource->fields['users_id_recipient'] = Session::getLoginUserID();
                        $resource->fields['users_id'] = $data["users_id_recipient"];
                        $resource->fields['date_declaration'] = date('Y-m-d');
                        $resource->fields['date_begin'] = null;
                        $resource->fields['date_end'] = null;
                        $resource->fields['plugin_resources_departments_id'] = $data['plugin_resources_departments_id'];
                        $resource->fields['locations_id'] = 0;
                        $resource->fields['is_leaving'] = 0;
                        $resource->fields['users_id_recipient_leaving'] = 0;
                        $resource->fields['comment'] = '';
                        $resource->fields['notepad'] = '';
                        $resource->fields['is_template'] = 0;
                        $resource->fields['template_name'] = '';
                        $resource->fields['is_deleted'] = 0;
                        $resource->fields['is_helpdesk_visible'] = 1;
                        $resource->fields['date_mod'] = date('Y-m-d');
                        $resource->fields['plugin_resources_resourcestates_id'] = 0;
                        $resource->fields['picture'] = null;
                        $resource->fields['is_recursive'] = 0;
                        $resource->fields['quota'] = 1;
                        $resource->fields['plugin_resources_resourcesituations_id'] = 0;
                        $resource->fields['plugin_resources_contractnatures_id'] = 0;
                        $resource->fields['plugin_resources_ranks_id'] = 0;
                        $resource->fields['plugin_resources_resourcespecialities_id'] = 0;
                        $resource->fields['plugin_resources_leavingreasons_id'] = 0;
                        if ($resourceItem->can(-1, 'w', $input)) {
                            $idResource = $resource->add($resource->fields);
                            if ($idResource) {
                                $resource->fields['id'] = $idResource;
                                if (isset($resourceItem->fields['id'])) {
                                    unset($resourceItem->fields['id']);
                                }
                                $resourceItem->fields['plugin_resources_resources_id'] = $idResource;
                                $resourceItem->fields['items_id'] = $user->fields['id'];
                                $resourceItem->fields['itemtype'] = $data['itemtype'];
                                $resourceItem->fields['comment'] = null;
                                $idResourceItem = $resourceItem->add($resourceItem->fields);
                                if ($idResourceItem) {
                                    // Cochage des checklist en mode "JOB DONE"
                                    $pChecklist = new PluginResourcesChecklist();
                                    $query = "UPDATE " . $pChecklist->getTable() . " SET `is_checked`=1 WHERE `plugin_resources_resources_id`=" . $idResource;
                                    if ($DB->query($query)) {
                                        $res['ok']++;
                                        $messageOk .= $user->fields['realname'] . " " . $user->fields['firstname'] . "<br/>";
                                    } else {
                                        $res['ko']++;
                                    }
                                } else {
                                    $res['ko']++;
                                    $messageKo .= $user->fields['realname'] . " " . $user->fields['firstname'] . "<br/>";
                                    $resource->delete($resource->fields, 1);
                                }
                            } else {
                                $res['ko']++;
                            }
                        } else {
                            $res['noright']++;
                        }
                    } else {
                        $messageKo .= $user->fields['realname'] . " " . $user->fields['firstname'] . "<br/>";
                        $res['ko']++;
                    }
                }
            }
            break;
    }
    if ($res['ko'] != 0) {
        if ($res['ko'] > 1) {
            $messageKo = _n("This resource aldready exists", "These resources aldready exist", 2, "resources") . ":<br/>" . $messageKo;
        } else {
            $messageKo = _n("This resource aldready exists", "These resources aldready exist", 1, "resources") . ":<br/>" . $messageKo;
        }
        Session::addMessageAfterRedirect($messageKo, true, ERROR);
    }
    if ($res['ok'] > 0) {
        if ($res['ok'] > 1) {
            $messageOk = _n("This resource has been added", "These resources have been added", 2, "resources") . ":<br/>" . $messageOk;
        } else {
            $messageOk = _n("This resource has been added", "These resources have been added", 1, "resources") . ":<br/>" . $messageOk;
        }
        Session::addMessageAfterRedirect($messageOk, true, INFO);
    }
    return $res;
}