コード例 #1
0
ファイル: wizard.form.php プロジェクト: geldarr/hack-space
     $values['target'] = Toolbox::getItemTypeFormURL('PluginResourcesWizard');
     $values['withtemplate'] = $_POST["withtemplate"];
     if (isset($_POST["second_step"])) {
         $values['new'] = 1;
     } else {
         if (isset($_POST["second_step_update"])) {
             $values['new'] = 0;
         }
     }
     $values["requiredfields"] = 1;
     $_SESSION["MESSAGE_AFTER_REDIRECT"] = "<h3><span class='red'>" . __('Required fields are not filled. Please try again.', 'resources') . "</span></h3>";
     Html::displayMessageAfterRedirect();
     $resource->wizardSecondForm($_POST["id"], $values);
 } else {
     if ($resource->canCreate() && isset($_POST["second_step"])) {
         $newID = $resource->add($_POST);
     } else {
         if ($resource->canCreate() && isset($_POST["second_step_update"])) {
             $resource->update($_POST);
             $newID = $_POST["id"];
         }
     }
     //if employee right : next step
     if ($newID) {
         $wizard_employee = PluginResourcesContractType::checkWizardSetup($newID, "use_employee_wizard");
         $wizard_need = PluginResourcesContractType::checkWizardSetup($newID, "use_need_wizard");
         $wizard_picture = PluginResourcesContractType::checkWizardSetup($newID, "use_picture_wizard");
         if ($employee->canCreate()) {
             if ($wizard_employee) {
                 $employee->wizardThirdForm($newID);
             } elseif ($wizard_need) {
コード例 #2
0
ファイル: hook.php プロジェクト: geldarr/hack-space
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;
}