コード例 #1
0
 protected static function UpdateAttachments($oObject, $oChange = null)
 {
     self::$m_bIsModified = false;
     if (utils::ReadParam('attachment_plugin', 'not-in-form') == 'not-in-form') {
         // Workaround to an issue in iTop < 2.0
         // Leave silently if there is no trace of the attachment form
         return;
     }
     $iTransactionId = utils::ReadParam('transaction_id', null);
     if (!is_null($iTransactionId)) {
         $aActions = array();
         $aAttachmentIds = utils::ReadParam('attachments', array());
         // Get all current attachments
         $oSearch = DBObjectSearch::FromOQL("SELECT Attachment WHERE item_class = :class AND item_id = :item_id");
         $oSet = new DBObjectSet($oSearch, array(), array('class' => get_class($oObject), 'item_id' => $oObject->GetKey()));
         while ($oAttachment = $oSet->Fetch()) {
             // Remove attachments that are no longer attached to the current object
             if (!in_array($oAttachment->GetKey(), $aAttachmentIds)) {
                 $oAttachment->DBDelete();
                 $aActions[] = self::GetActionDescription($oAttachment, false);
             }
         }
         // Attach new (temporary) attachements
         $sTempId = session_id() . '_' . $iTransactionId;
         // The object is being created from a form, check if there are pending attachments
         // for this object, but deleting the "new" ones that were already removed from the form
         $aRemovedAttachmentIds = utils::ReadParam('removed_attachments', array());
         $sOQL = 'SELECT Attachment WHERE temp_id = :temp_id';
         $oSearch = DBObjectSearch::FromOQL($sOQL);
         foreach ($aAttachmentIds as $iAttachmentId) {
             $oSet = new DBObjectSet($oSearch, array(), array('temp_id' => $sTempId));
             while ($oAttachment = $oSet->Fetch()) {
                 if (in_array($oAttachment->GetKey(), $aRemovedAttachmentIds)) {
                     $oAttachment->DBDelete();
                     // temporary attachment removed, don't even mention it in the history
                 } else {
                     $oAttachment->SetItem($oObject);
                     $oAttachment->Set('temp_id', '');
                     $oAttachment->DBUpdate();
                     // temporary attachment confirmed, list it in the history
                     $aActions[] = self::GetActionDescription($oAttachment, true);
                 }
             }
         }
         if (count($aActions) > 0) {
             if ($oChange == null) {
                 // Let's create a change if non is supplied
                 $oChange = MetaModel::NewObject("CMDBChange");
                 $oChange->Set("date", time());
                 $sUserString = CMDBChange::GetCurrentUserName();
                 $oChange->Set("userinfo", $sUserString);
                 $iChangeId = $oChange->DBInsert();
             }
             foreach ($aActions as $sActionDescription) {
                 self::RecordHistory($oChange, $oObject, $sActionDescription);
             }
             self::$m_bIsModified = true;
         }
     }
 }
コード例 #2
0
         $aResult['error'] = "Missing argument 'obj_class'";
     } elseif (empty($sTempId)) {
         $aResult['error'] = "Missing argument 'temp_id'";
     } else {
         try {
             $oDoc = utils::ReadPostedDocument('file');
             $oAttachment = MetaModel::NewObject('Attachment');
             $oAttachment->Set('expire', time() + 3600);
             // one hour...
             $oAttachment->Set('temp_id', $sTempId);
             $oAttachment->Set('item_class', $sObjClass);
             $oAttachment->SetDefaultOrgId();
             $oAttachment->Set('contents', $oDoc);
             $iAttId = $oAttachment->DBInsert();
             $aResult['msg'] = $oDoc->GetFileName();
             $aResult['icon'] = utils::GetAbsoluteUrlAppRoot() . AttachmentPlugIn::GetFileIcon($oDoc->GetFileName());
             $aResult['att_id'] = $iAttId;
             $aResult['preview'] = $oDoc->IsPreviewAvailable() ? 'true' : 'false';
         } catch (FileUploadException $e) {
             $aResult['error'] = $e->GetMessage();
         }
     }
     $oPage->add(json_encode($aResult));
     break;
 case 'remove':
     $iAttachmentId = utils::ReadParam('att_id', '');
     $oSearch = DBObjectSearch::FromOQL("SELECT Attachment WHERE id = :id");
     $oSet = new DBObjectSet($oSearch, array(), array('id' => $iAttachmentId));
     while ($oAttachment = $oSet->Fetch()) {
         $oAttachment->DBDelete();
     }
コード例 #3
0
ファイル: index.php プロジェクト: kira8565/ITOP203-ZHCN
/**
 * Displays the details of a request
 * @param WebPage $oP The current web page
 * @param Object $oObj The target object
 * @return void
 */
function ShowDetailsRequest(WebPage $oP, $oObj)
{
    $sClass = get_class($oObj);
    $sLogAttCode = GetConstant($sClass, 'PUBLIC_LOG');
    $sUserCommentAttCode = GetConstant($sClass, 'USER_COMMENT');
    $bIsReopenButton = false;
    $bIsCloseButton = false;
    $bIsEscalateButton = false;
    $bEditAttachments = false;
    $aEditAtt = array();
    // List of attributes editable in the main form
    if (!MetaModel::DBIsReadOnly()) {
        switch ($oObj->GetState()) {
            case 'resolved':
                $aEditAtt = array();
                $aTransitions = $oObj->EnumTransitions();
                $oSet = DBObjectSet::FromObject($oObj);
                // Add the "Reopen" button if this is valid action
                if (array_key_exists('ev_reopen', $aTransitions) && UserRights::IsStimulusAllowed($sClass, 'ev_reopen', $oSet)) {
                    $bIsReopenButton = true;
                    MakeStimulusForm($oP, $oObj, 'ev_reopen', array($sLogAttCode));
                }
                // Add the "Close" button if this is valid action
                if (array_key_exists('ev_close', $aTransitions) && UserRights::IsStimulusAllowed($sClass, 'ev_close', $oSet)) {
                    $bIsCloseButton = true;
                    MakeStimulusForm($oP, $oObj, 'ev_close', array('user_satisfaction', $sUserCommentAttCode));
                }
                break;
            case 'closed':
                // By convention 'closed' is the final state of a ticket and nothing can be done in such a state
                break;
            default:
                // In all other states, the only possible action is to update the ticket (both the case log and the attachments)
                // This update is possible only if the case log field is not read-only or hidden in the current state
                $iFlags = $oObj->GetAttributeFlags($sLogAttCode);
                $bReadOnly = ($iFlags & (OPT_ATT_READONLY | OPT_ATT_HIDDEN)) != 0;
                if ($bReadOnly) {
                    $aEditAtt = array();
                    $bEditAttachments = false;
                } else {
                    $aEditAtt = array($sLogAttCode => '????');
                    $bEditAttachments = true;
                }
                break;
        }
    }
    // REFACTORISER LA MISE EN FORME
    $oP->add("<h1 id=\"title_request_details\">" . $oObj->GetIcon() . "&nbsp;" . Dict::Format('Portal:TitleRequestDetailsFor_Request', $oObj->GetName()) . "</h1>\n");
    $aAttList = json_decode(GetConstant($sClass, 'DETAILS_ZLIST'), true);
    switch ($oObj->GetState()) {
        case 'closed':
            $aAttList['centered'][] = 'user_satisfaction';
            $aAttList['centered'][] = $sUserCommentAttCode;
    }
    // Remove the edited attribute from the shown attributes
    //
    foreach ($aEditAtt as $sAttCode => $foo) {
        foreach ($aAttList as $col => $aColumn) {
            if (in_array($sAttCode, $aColumn)) {
                if (($index = array_search($sAttCode, $aColumn)) !== false) {
                    unset($aAttList[$col][$index]);
                }
            }
        }
    }
    $oP->add("<div class=\"wizContainer\" id=\"form_commment_request\">\n");
    $oP->WizardFormStart('request_form', null);
    $oP->add('<div id="request_details">');
    $oP->add('<table id="request_details_table">');
    $oP->add('<tr>');
    $oP->add('<td style="vertical-align:top;">');
    $oP->DisplayObjectDetails($oObj, $aAttList['col:left']);
    $oP->add('</td>');
    $oP->add('<td style="vertical-align:top;">');
    $oP->DisplayObjectDetails($oObj, $aAttList['col:right']);
    $oP->add('</td>');
    $oP->add('</tr>');
    if (array_key_exists('centered', $aAttList)) {
        $oP->add('<tr>');
        $oP->add('<td style="vertical-align:top;" colspan="2">');
        $oP->DisplayObjectDetails($oObj, $aAttList['centered']);
        $oP->add('</td>');
        $oP->add('</tr>');
    }
    // REFACTORISER
    $oP->add('<tr>');
    $oP->add('<td colspan="2" style="vertical-align:top;">');
    $oAttPlugin = new AttachmentPlugIn();
    if ($bEditAttachments) {
        $oAttPlugin->EnableDelete(false);
        $oAttPlugin->OnDisplayRelations($oObj, $oP, true);
    } else {
        $oAttPlugin->OnDisplayRelations($oObj, $oP, false);
    }
    $oP->add('</td>');
    $oP->add('</tr>');
    $oP->add('<tr>');
    $oP->add('<td colspan="2" style="vertical-align:top;">');
    //$oP->add("<form action=\"../portal/index.php\" id=\"request_form\" method=\"post\">\n");
    //$oP->add('<table id=""><tr><td style="vertical-align:top;">');
    //$oP->add("<h1 id=\"title_request_details\">".Dict::Format('Portal:CommentsFor_Request', $oObj->GetName())."</h1>\n");
    $oP->add("<input type=\"hidden\" name=\"class\" value=\"{$sClass}\">");
    $oP->add("<input type=\"hidden\" name=\"id\" value=\"" . $oObj->GetKey() . "\">");
    $oP->add("<input type=\"hidden\" name=\"operation\" value=\"update_request\">");
    $oP->add("<input type=\"hidden\" id=\"stimulus_to_apply\" name=\"apply_stimulus\" value=\"\">\n");
    $oP->add_script(<<<EOF
\tfunction SetStimulusToApply(sStimulusCode)
\t{
\t\t\$('#stimulus_to_apply').val(sStimulusCode);
\t}
EOF
);
    $aEditFields = array();
    // Intermediate array to avoid code duplication while splitting btw ticket_log and the rest
    foreach ($aEditAtt as $sAttCode => $foo) {
        $sValue = $oObj->Get($sAttCode);
        $sDisplayValue = $oObj->GetEditValue($sAttCode);
        $aArgs = array('this' => $oObj, 'formPrefix' => '');
        $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
        $sInputId = 'input_' . $sAttCode;
        $sHTMLValue = "<span id=\"field_{$sInputId}\">" . cmdbAbstractObject::GetFormElementForField($oP, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', 0, $aArgs) . '</span>';
        $aEditFields[$sAttCode] = array('label' => MetaModel::GetLabel($sClass, $sAttCode), 'value' => $sHTMLValue);
    }
    foreach ($aEditFields as $sAttCode => $aFieldSpec) {
        if ($sAttCode == $sLogAttCode) {
            // Skip, the public log will be displayed below the buttons
            continue;
        }
        $oP->add("<div class=\"edit_item\">");
        $oP->add('<h1>' . $aFieldSpec['label'] . '</h1>');
        $oP->add($aFieldSpec['value']);
        $oP->add('</div>');
    }
    if ($bIsReopenButton) {
        $sStimulusCode = 'ev_reopen';
        $sTitle = addslashes(Dict::S('Portal:Button:ReopenTicket'));
        $sOk = addslashes(Dict::S('UI:Button:Ok'));
        $oP->p('<input type="button" onClick="RunStimulusDialog(\'' . $sStimulusCode . '\', \'' . $sTitle . '\', \'' . $sOk . '\');" value="' . $sTitle . '...">');
    }
    if ($bIsCloseButton) {
        $sStimulusCode = 'ev_close';
        $sTitle = addslashes(Dict::S('Portal:Button:CloseTicket'));
        $sOk = addslashes(Dict::S('UI:Button:Ok'));
        $oP->p('<input type="button" onClick="RunStimulusDialog(\'' . $sStimulusCode . '\', \'' . $sTitle . '\', \'' . $sOk . '\');" value="' . $sTitle . '...">');
    } elseif (count($aEditAtt) > 0) {
        $oP->p('<input type="submit" value="' . Dict::S('Portal:Button:UpdateRequest') . '">');
    }
    if ($bIsEscalateButton) {
        $sStimulusCode = 'ev_timeout';
        $oP->p('<input type="submit" onClick="SetStimulusToApply(\'' . $sStimulusCode . '\');" value="' . Dict::S('Portal:ButtonEscalate') . '">');
    }
    $oP->add('</td>');
    $oP->add('</tr>');
    $oP->add('<tr>');
    $oP->add('<td colspan="2" style="vertical-align:top;">');
    if (isset($aEditFields[$sLogAttCode])) {
        $oP->add("<div class=\"edit_item\">");
        $oP->add('<h1>' . $aEditFields[$sLogAttCode]['label'] . '</h1>');
        $oP->add($aEditFields[$sLogAttCode]['value']);
        $oP->add('</div>');
    } else {
        $oP->add('<h1>' . MetaModel::GetLabel($sClass, $sLogAttCode) . '</h1>');
        $oP->add($oObj->GetAsHTML($sLogAttCode));
    }
    $oP->add('</td>');
    $oP->add('</tr>');
    $oP->add('</table>');
    $oP->add('</div>');
    $oP->WizardFormEnd();
    $oP->add('</div>');
}