Profile::prepareInputForUpdate PHP Method

prepareInputForUpdate() public method

public prepareInputForUpdate ( $input )
    function prepareInputForUpdate($input)
    {
        if (isset($input["_helpdesk_item_types"])) {
            if (!isset($input["helpdesk_item_type"]) || !is_array($input["helpdesk_item_type"])) {
                $input["helpdesk_item_type"] = array();
            }
            // Linear_HIT: $input["helpdesk_item_type"] = array_keys($input["helpdesk_item_type"]
            $input["helpdesk_item_type"] = exportArrayToDB($input["helpdesk_item_type"]);
        }
        if (isset($input['helpdesk_hardware']) && is_array($input['helpdesk_hardware'])) {
            $helpdesk_hardware = 0;
            foreach ($input['helpdesk_hardware'] as $right => $value) {
                if ($value) {
                    $helpdesk_hardware += $right;
                }
            }
            $input['helpdesk_hardware'] = $helpdesk_hardware;
        }
        if (isset($input["_cycle_ticket"])) {
            $tab = Ticket::getAllStatusArray();
            $cycle = array();
            foreach ($tab as $from => $label) {
                foreach ($tab as $dest => $label) {
                    if ($from != $dest && (!isset($input["_cycle_ticket"][$from][$dest]) || $input["_cycle_ticket"][$from][$dest] == 0)) {
                        $cycle[$from][$dest] = 0;
                    }
                }
            }
            $input["ticket_status"] = exportArrayToDB($cycle);
        }
        if (isset($input["_cycle_problem"])) {
            $tab = Problem::getAllStatusArray();
            $cycle = array();
            foreach ($tab as $from => $label) {
                foreach ($tab as $dest => $label) {
                    if ($from != $dest && $input["_cycle_problem"][$from][$dest] == 0) {
                        $cycle[$from][$dest] = 0;
                    }
                }
            }
            $input["problem_status"] = exportArrayToDB($cycle);
        }
        if (isset($input["_cycle_change"])) {
            $tab = Change::getAllStatusArray();
            $cycle = array();
            foreach ($tab as $from => $label) {
                foreach ($tab as $dest => $label) {
                    if ($from != $dest && $input["_cycle_change"][$from][$dest] == 0) {
                        $cycle[$from][$dest] = 0;
                    }
                }
            }
            $input["change_status"] = exportArrayToDB($cycle);
        }
        $this->profileRight = array();
        foreach (ProfileRight::getAllPossibleRights() as $right => $default) {
            if (isset($input['_' . $right])) {
                if (!is_array($input['_' . $right])) {
                    $input['_' . $right] = array('1' => $input['_' . $right]);
                }
                $newvalue = 0;
                foreach ($input['_' . $right] as $value => $valid) {
                    if ($valid) {
                        if (($underscore_pos = strpos($value, '_')) !== false) {
                            $value = substr($value, 0, $underscore_pos);
                        }
                        $newvalue += $value;
                    }
                }
                // Update rights only if changed
                if (!isset($this->fields[$right]) || $this->fields[$right] != $newvalue) {
                    $this->profileRight[$right] = $newvalue;
                }
                unset($input['_' . $right]);
            }
        }
        // check if right if the last write profile on Profile object
        if ($this->fields['profile'] & UPDATE && isset($input['profile']) && !($input['profile'] & UPDATE) && countElementsInTable("glpi_profilerights", "`name` = 'profile' AND `rights` & " . UPDATE)) {
            Session::addMessageAfterRedirect(__("This profile is the last with write rights on profiles"), false, ERROR);
            Session::addMessageAfterRedirect(__("Deletion refused"), false, ERROR);
            unset($input["profile"]);
        }
        return $input;
    }