Example #1
0
/**
    * Update page
*/
function display_update_page($draftid = -1)
{
    global $id;
    global $incidentid;
    global $action;
    global $CONFIG;
    global $iconset;
    global $now;
    global $dbDrafts;
    global $sit;
    if ($draftid != -1) {
        $draftsql = "SELECT * FROM `{$dbDrafts}` WHERE id = {$draftid}";
        $draftresult = mysql_query($draftsql);
        if (mysql_error()) {
            trigger_error(mysql_error(), E_USER_WARNING);
        }
        $draftobj = mysql_fetch_object($draftresult);
        $metadata = explode("|", $draftobj->meta);
    }
    // No update body text detected show update form
    ?>
    <script type="text/javascript">
    <!--
    function deleteOption(object) {
        var Current = object.updatetype.selectedIndex;
        object.updatetype.options[Current] = null;
    }

    function notarget(object)
    {
        // remove last option
        var length = object.updatetype.length;
        if (length > 6)
        {
            object.updatetype.selectedIndex=6;
            var Current = object.updatetype.selectedIndex;
            object.updatetype.options[Current] = null;
        }
        object.priority.value=object.storepriority.value;
        //object.priority.disabled=true;
        object.priority.disabled=false;
        object.updatetype.selectedIndex=0;
        object.updatetype.disabled=false;
    }


    function initialresponse(object)
    {
        // remove last option
        var length = object.updatetype.length;
        if (length > 6)
        {
            object.updatetype.selectedIndex=6;
            var Current = object.updatetype.selectedIndex;
            object.updatetype.options[Current] = null;
        }
        object.priority.value=object.storepriority.value;
        object.priority.disabled=true;
        object.updatetype.selectedIndex=0;
        object.updatetype.disabled=false;
    }


    function actionplan(object)
    {
        // remove last option
        var length = object.updatetype.length;
        if (length > 6)
        {
            object.updatetype.selectedIndex=6;
            var Current = object.updatetype.selectedIndex;
            object.updatetype.options[Current] = null;
        }

        var defaultSelected = true;
        var selected = true;
        var optionName = new Option('Action Plan', 'actionplan', defaultSelected, selected)
        var length = object.updatetype.length;
        object.updatetype.options[length] = optionName;
        object.priority.value=object.storepriority.value;
        object.priority.disabled=true;
        object.updatetype.disabled=true;
    }

    function reprioritise(object)
    {
        // remove last option
        var length = object.updatetype.length;
        if (length > 6)
        {
            object.updatetype.selectedIndex=6;
            var Current = object.updatetype.selectedIndex;
            object.updatetype.options[Current] = null;
        }
        // add new option
        var defaultSelected = true;
        var selected = true;
        var optionName = new Option('Reprioritise', 'solution', defaultSelected, selected)
        var length = object.updatetype.length;
        object.updatetype.options[length] = optionName;
        object.priority.disabled=false;
        document.updateform.priority.disabled=false;
        object.updatetype.disabled=true;
    }

    function probdef(object)
    {
        // remove last option
        var length = object.updatetype.length;
        if (length > 6)
        {
            object.updatetype.selectedIndex=6;
            var Current = object.updatetype.selectedIndex;
            object.updatetype.options[Current] = null;
        }

        var defaultSelected = true;
        var selected = true;
        var optionName = new Option('Problem Definition', 'probdef', defaultSelected, selected)
        var length = object.updatetype.length;
        object.updatetype.options[length] = optionName;
        object.priority.value=object.storepriority.value;
        object.priority.disabled=true;
        object.updatetype.disabled=true;
    }

    function replaceOption(object) {
        var Current = object.updatetype.selectedIndex;
        object.updatetype.options[Current].text = object.currentText.value;
        object.updatetype.options[Current].value = object.currentText.value;
    }

    <?php 
    echo "var draftid = {$draftid}";
    ?>

    // Auto save
    function save_content(){
        var xmlhttp=false;

        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
            try {
                xmlhttp = new XMLHttpRequest();
            } catch (e) {
                xmlhttp=false;
            }
        }
        if (!xmlhttp && window.createRequest) {
            try {
                xmlhttp = window.createRequest();
            } catch (e) {
                xmlhttp=false;
            }
        }

        var toPass = $('updatelog').value;
        //alert(toPass.value);

        var meta = $('target').value+"|"+$('updatetype').value+"|"+$('cust_vis').checked+"|";
        meta += $('priority').value+"|"+$('newstatus').value+"|"+$('nextaction').value+"|";

        if (toPass != '')
        {
            // xmlhttp.open("GET", "ajaxdata.php?action=auto_save&userid="+<?php 
    echo $_SESSION['userid'];
    ?>
+"&type=update&incidentid="+<?php 
    echo $id;
    ?>
+"&draftid="+draftid+"&meta="+meta+"&content="+escape(toPass), true);
            var url = "ajaxdata.php";
            var params = "action=auto_save&userid="+<?php 
    echo $_SESSION['userid'];
    ?>
+"&type=update&incidentid="+<?php 
    echo $id;
    ?>
+"&draftid="+draftid+"&meta="+meta+"&content="+escape(toPass);
            xmlhttp.open("POST", url, true)
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlhttp.setRequestHeader("Content-length", params.length);
            xmlhttp.setRequestHeader("Connection", "close");

            xmlhttp.onreadystatechange=function() {
                //remove this in the future after testing
                if (xmlhttp.readyState==4) {
                    if (xmlhttp.responseText != ''){
                        //alert(xmlhttp.responseText);
                        if (draftid == -1)
                        {
                            draftid = xmlhttp.responseText;
                            $('draftid').value = draftid;
                        }
                        var currentTime = new Date();
                        var hours = currentTime.getHours();
                        var minutes = currentTime.getMinutes();
                        if (minutes < 10)
                        {
                            minutes = "0"+minutes;
                        }
                        var seconds = currentTime.getSeconds();
                        if (seconds < 10)
                        {
                            seconds = "0"+seconds;
                        }
                        $('updatestr').innerHTML = '<?php 
    echo "<a href=\"javascript:save_content();\">" . icon('save', 16, $GLOBALS['strSaveDraft']) . "</a> " . icon('info', 16, $GLOBALS['strDraftLastSaved']) . " ";
    ?>
' + hours + ':' + minutes + ':' + seconds;
                    }
                }
            }
            xmlhttp.send(params);
        }
    }

    setInterval("save_content()", 10000); //every 10 seconds

    //-->
    </script>
    <?php 
    echo show_form_errors('update');
    clear_form_errors('update');
    //echo "<form action='".$_SERVER['PHP_SELF']."?id={$id}&amp;draftid={$draftid}' method='post' name='updateform' id='updateform' enctype='multipart/form-data'>";
    echo "<form action='" . $_SERVER['PHP_SELF'] . "?id={$id}' method='post' name='updateform' id='updateform' enctype='multipart/form-data'>";
    echo "<table class='vertical'>";
    echo "<tr>";
    echo "<th align='right' width='20%;'>{$GLOBALS['strSLATarget']}";
    echo icon('sla', 16) . "</th>";
    echo "<td class='shade2'>";
    $target = incident_get_next_target($id);
    $targetNone = '';
    $targetInitialresponse = '';
    $targetProbdef = '';
    $targetActionplan = '';
    $targetSolution = '';
    $typeResearch = '';
    $typeEmailin = '';
    $typeEmailout = '';
    $typePhonecallin = '';
    $typePhonecallout = '';
    $typeExternalinfo = '';
    $typeReviewmet = '';
    if (!empty($metadata)) {
        switch ($metadata[0]) {
            case 'none':
                $targetNone = " SELECTED ";
                break;
            case 'initialresponse':
                $targetInitialresponse = " SELECTED ";
                break;
            case 'probdef':
                $targetProbdef = " SELECTED ";
                break;
            case 'actionplan':
                $targetActionplan = " SELECTED ";
                break;
            case 'solution':
                $targetSolution = " SELECTED ";
                break;
        }
        switch ($metadata[1]) {
            case 'research':
                $typeResearch = " SELECTED ";
                break;
            case 'emailin':
                $typeEmailin = " SELECTED ";
                break;
            case 'emailout':
                $typeEmailout = " SELECTED ";
                break;
            case 'phonecallin':
                $typePhonecallin = " SELECTED ";
                break;
            case 'phonecallout':
                $typePhonecallout = " SELECTED ";
                break;
            case 'externalinfo':
                $typeExternalinfo = " SELECTED ";
                break;
            case 'reviewmet':
                $typeReviewmet = " SELECTED ";
                break;
        }
    }
    echo "<select name='target' id='target' class='dropdown'>\n";
    echo "<option value='none' {$targetNone} onclick='notarget(this.form)'>{$GLOBALS['strNone']}</option>\n";
    switch ($target->type) {
        case 'initialresponse':
            echo "<option value='initialresponse' {$targetInitialresponse} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/initialresponse.png); background-repeat: no-repeat;' onclick='initialresponse(this.form)' >{$GLOBALS['strInitialResponse']}</option>\n";
            echo "<option value='probdef' {$targetProbdef} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/probdef.png); background-repeat: no-repeat;' onclick='probdef(this.form)'>{$GLOBALS['strProblemDefinition']}</option>\n";
            echo "<option value='actionplan' {$targetActionplan} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/actionplan.png); background-repeat: no-repeat;' onclick='actionplan(this.form)'>{$GLOBALS['strActionPlan']}</option>\n";
            echo "<option value='solution' {$targetSolution} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/solution.png); background-repeat: no-repeat;' onclick='reprioritise(this.form)'>{$GLOBALS['strResolutionReprioritisation']}</option>\n";
            break;
        case 'probdef':
            echo "<option value='probdef' {$targetProbdef} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/probdef.png); background-repeat: no-repeat;' onclick='probdef(this.form)'>{$GLOBALS['strProblemDefinition']}</option>\n";
            echo "<option value='actionplan' {$targetActionplan} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/actionplan.png); background-repeat: no-repeat;' onclick='actionplan(this.form)'>{$GLOBALS['strActionPlan']}</option>\n";
            echo "<option value='solution' {$targetSolution} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/solution.png); background-repeat: no-repeat;' onclick='reprioritise(this.form)'>{$GLOBALS['strResolutionReprioritisation']}</option>\n";
            break;
        case 'actionplan':
            echo "<option value='actionplan' {$targetActionplan} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/actionplan.png); background-repeat: no-repeat;' onclick='actionplan(this.form)'>{$GLOBALS['strActionPlan']}</option>\n";
            echo "<option value='solution' {$targetSolution} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/solution.png); background-repeat: no-repeat;' onclick='reprioritise(this.form)'>{$GLOBALS['strResolutionReprioritisation']}</option>\n";
            break;
        case 'solution':
            echo "<option value='solution' {$targetSolution} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/solution.png); background-repeat: no-repeat;' onclick='reprioritise(this.form)'>{$GLOBALS['strResolutionReprioritisation']}</option>\n";
            break;
    }
    echo "</select>\n";
    echo "</td></tr>\n";
    echo "<tr><th align='right'>{$GLOBALS['strUpdateType']}</th>";
    echo "<td class='shade1'>";
    echo "<select name='updatetype' id='updatetype' class='dropdown'>";
    /*
    if ($target->type!='actionplan' && $target->type!='solution')
        echo "<option value='probdef'>Problem Definition</option>\n";
    if ($target->type!='solution')
        echo "<option value='actionplan'>Action Plan</option>\n";
    */
    echo "<option value='research' {$typeResearch} selected='selected' style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/research.png); background-repeat: no-repeat;'>{$GLOBALS['strResearchNotes']}</option>\n";
    echo "<option value='emailin' {$typeEmailin} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/emailin.png); background-repeat: no-repeat;'>{$GLOBALS['strEmailFromCustomer']}</option>\n";
    echo "<option value='emailout' {$typeEmailout} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/emailout.png); background-repeat: no-repeat;'>{$GLOBALS['strEmailToCustomer']}</option>\n";
    echo "<option value='phonecallin' {$typePhonecallin} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/callin.png); background-repeat: no-repeat;'>{$GLOBALS['strCallFromCustomer']}</option>\n";
    echo "<option value='phonecallout' {$typePhonecallout} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/callout.png); background-repeat: no-repeat;'>{$GLOBALS['strCallToCustomer']}</option>\n";
    echo "<option value='externalinfo' {$typeExternalinfo} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/externalinfo.png); background-repeat: no-repeat;'>{$GLOBALS['strExternalInfo']}</option>\n";
    echo "<option value='reviewmet' {$typeReviewmet} style='text-indent: 15px; height: 17px; background-image: url({$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/review.png); background-repeat: no-repeat;'>{$GLOBALS['strReview']}</option>\n";
    echo "</select>";
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<th align='right'>{$GLOBALS['strUpdate']}<br />";
    echo "<span class='required'>{$GLOBALS['strRequired']}</span></th>";
    echo "<td class='shade1'>";
    $checkbox = '';
    if (!empty($metadata)) {
        if ($metadata[2] == "true") {
            $checkbox = "checked='checked'";
        }
    } else {
        $checkbox = "checked='checked'";
    }
    echo "<label><input type='checkbox' name='cust_vis' id='cust_vis' ";
    echo "{$checkbox} value='yes' /> {$GLOBALS['strMakeVisibleInPortal']}<label><br />";
    echo bbcode_toolbar('updatelog');
    echo "<textarea name='bodytext' id='updatelog' rows='13' cols='50'>";
    if ($draftid != -1) {
        echo $draftobj->content;
    }
    echo "</textarea>";
    echo "<div id='updatestr'><a href='javascript:save_content();'>" . icon('save', 16, $GLOBALS['strSaveDraft']) . "</a></div>";
    echo "</td></tr>";
    if ($target->type == 'initialresponse') {
        $disable_priority = TRUE;
    } else {
        $disable_priority = FALSE;
    }
    echo "<tr><th align='right'>{$GLOBALS['strNewPriority']}</th>";
    echo "<td class='shade1'>";
    //    // FIXME fix maximum priority
    //    $servicelevel=maintenance_servicelevel(incident_maintid($id));
    //    if ($servicelevel == 2 || $servicelevel == 5) $maxpriority = 4;
    //    else $maxpriority = 3;
    $maxpriority = 4;
    $setPriorityTo = incident_priority($id);
    if (!empty($metadata)) {
        $setPriorityTo = $metadata[3];
    }
    echo priority_drop_down("newpriority", $setPriorityTo, $maxpriority, $disable_priority);
    //id='priority
    echo "</td></tr>\n";
    echo "<tr>";
    echo "<th align='right'>{$GLOBALS['strNewStatus']}</th>";
    $setStatusTo = incident_status($id);
    $disabled = FALSE;
    //we do this so if you update another user's incident, it defaults to active
    if ($sit[2] != incident_owner($incidentid)) {
        $setStatusTo = '0';
    } elseif (!empty($metadata)) {
        $setStatusTo = $metadata[4];
    }
    echo "<td class='shade1'>" . incidentstatus_drop_down("newstatus", $setStatusTo) . "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<th align='right'>{$GLOBALS['strNextAction']}</th>";
    $nextAction = '';
    if (!empty($metadata)) {
        $nextAction = $metadata[5];
    }
    echo "<td class='shade2'><input type='text' name='nextaction' ";
    echo "id='nextaction' maxlength='50' size='30' value='{$nextAction}' /></td></tr>";
    echo "<tr>";
    echo "<th align='right'>";
    echo "<strong>{$GLOBALS['strTimeToNextAction']}</strong></th>";
    echo "<td class='shade2'>";
    echo show_next_action();
    echo "</td></tr>";
    echo "<tr>";
    // calculate upload filesize
    $att_file_size = readable_file_size($CONFIG['upload_max_filesize']);
    echo "<th align='right'>{$GLOBALS['strAttachFile']}";
    echo " (&lt;{$att_file_size})</th>";
    echo "<td class='shade1'><input type='hidden' name='MAX_FILE_SIZE' value='{$CONFIG['upload_max_filesize']}' />";
    echo "<input type='file' name='attachment' size='40' maxfilesize='{$CONFIG['upload_max_filesize']}' /></td>";
    echo "</tr>";
    echo "</table>";
    echo "<p class='center'>";
    echo "<input type='hidden' name='action' value='update' />";
    if ($draftid == -1) {
        $localdraft = '';
    } else {
        $localdraft = $draftid;
    }
    echo "<input type='hidden' name='draftid' id='draftid' value='{$localdraft}' />";
    echo "<input type='hidden' name='storepriority' value='" . incident_priority($id) . "' />";
    echo "<input type='submit' name='submit' value='{$GLOBALS['strUpdateIncident']}' /></p>";
    echo "</form>";
}
if ($allow_reopen == 'yes') {
    if (empty($submit)) {
        // No submit detected show update form
        $incident_title = incident_title($id);
        $title = "{$strReopen}: " . $id . " - " . $incident_title;
        include APPLICATION_INCPATH . 'incident_html_top.inc.php';
        echo "<h2>{$strReopenIncident}</h2>";
        if (!empty($updateid)) {
            $action = "&updateid={$updateid}";
        }
        echo "<form action='{$_SERVER['PHP_SELF']}?id={$id}{$action}' method='post'>";
        if (empty($updateid)) {
            echo "<table class='vertical'>";
            echo "<tr><th>{$strUpdate}</th><td><textarea name='bodytext' rows='20' ";
            echo "cols='60'></textarea></td></tr>";
            echo "<tr><th>{$strStatus}</th><td>" . incidentstatus_drop_down("newstatus", 1);
            echo "</td></tr>\n";
            echo "</table>";
        } else {
            echo "<p align='center'>{$strReopenIncidentAndAddUpdate}</p>";
        }
        echo "<p><input name='submit' type='submit' value='{$strReopen}' /></p>";
        echo "</form>";
        include APPLICATION_INCPATH . 'incident_html_bottom.inc.php';
    } else {
        $reopen = reopen_incident($id);
        $move = true;
        // Default so we dont get an error if there is no updateid on a reopen (as is the case when reopening from incident_details)
        if (!empty($updateid)) {
            $move = move_update_to_incident($updateid, $id) and delete_holding_queue_update($updateid);
        }
                echo "{$strAssignTemporarilyTo} <strong>{$strYou}</strong> ({$_SESSION['realname']})</label><br />";
                echo "<label><input type='checkbox' name='tempnewowner' value='yes'  /> ";
                echo "{$strAssignTemporarily}</label>";
                echo "</td></tr>";
            } else {
                echo "<tr><th>{$strTemporaryOwner}:</th><td><label><input type='checkbox' name='temporary' value='yes' ";
                if ($sit[2] != $incident->owner and $sit[2] != $incident->towner) {
                    echo "disabled='disabled' ";
                }
                echo "/> ";
                if ($incident->towner > 0) {
                    echo "{$strChangeTemporaryOwner}";
                } else {
                    echo "{$strAssignTemporarily}";
                }
                echo "</label></td></tr>\n";
            }
            echo "<tr><th>{$strVisibility}:</th><td><label>";
            echo "<input type='checkbox' name='cust_vis' value='yes' /> {$strVisibleToCustomer}</label></td></tr>\n";
            echo "<tr><th>{$strNewIncidentStatus}:</th>";
            echo "<td>" . incidentstatus_drop_down("newstatus", $incident->status) . "</td></tr>\n";
            echo "</table>\n\n";
            echo "<input type='hidden' name='action' value='save' />";
            echo "<p align='center'><input name='submit' type='submit' value=\"{$strReassign}\" /></p>";
            echo "</form>\n";
        } else {
            echo "<p class='warning'>{$strNoRecords}</p>";
            // FIXME 3.41 better message here
        }
        include APPLICATION_INCPATH . 'incident_html_bottom.inc.php';
}
         echo "value='no' checked='yes' />{$strNo}</label> ";
         echo "<label><input type='radio' name='chase_customer' ";
         echo "value='yes' />{$strYes}</label>";
         echo "</td></tr>";
     }
     if ($obj->type == 'auto_chase_manager') {
         echo "<tr><th>{$strManagerChaseUpdate}</th>";
         echo "<label><input type='radio' name='chase_manager' ";
         echo "value='no' checked='yes' />{$strNo}</label> ";
         echo "<label><input type='radio' name='chase_manager' ";
         echo "value='yes' />{$strYes}</label>";
         echo "</td></tr>";
     }
 }
 echo "<tr><th>{$strNewIncidentStatus}:</th><td>";
 echo incidentstatus_drop_down("newincidentstatus", incident_status($id));
 echo "</td></tr>\n";
 echo "<tr><th>{$strTimeToNextAction}:</th>";
 echo "<td>";
 echo show_next_action('updateform');
 echo "</td>";
 echo "<br />";
 echo "</td></tr>";
 plugin_do('incident_email_form1');
 echo "</table>";
 echo "<p align='center'>";
 echo "<input type='hidden' name='step' value='2' />";
 echo "<input type='hidden' name='menu' value='{$menu}' />";
 echo "<input name='submit1' type='submit' value='{$strContinue}' /></p>";
 echo "</form>\n";
 include APPLICATION_INCPATH . 'incident_html_bottom.inc.php';