foreach ($a_projectBindedRsrces as $s_type => $a_miteRsrces) {
    foreach ($a_miteRsrces as $i_rsrc_id => $a_rsrc) {
        $a_selectBoxesNewTimeEntry[$s_type] .= "<option value='" . $i_rsrc_id . "'>" . $a_rsrc['name'] . "</option>";
    }
}
# add unbinded resources as select box entries if any
foreach ($a_projectUnbindedRsrces as $s_type => $a_miteRsrces) {
    $s_unbindedRsrces = '';
    foreach ($a_miteRsrces as $i_miteRsrc_id => $a_rsrc) {
        $s_unbindedRsrces .= "<option value='{$i_miteRsrc_id}'>" . $a_rsrc['name'] . "</option>";
    }
    if (!empty($a_projectBindedRsrces[$s_type])) {
        $a_selectBoxesNewTimeEntry[$s_type] .= "<optgroup label='" . lang_get('plugin_mite_other_' . $s_type) . "'>" . $s_unbindedRsrces . "</optgroup>";
    } else {
        $a_selectBoxesNewTimeEntry[$s_type] .= $s_unbindedRsrces;
    }
}
# wrap the available entries with the HTML select tag
$a_selectBoxesNewTimeEntry[Mantis2mitePlugin::API_RSRC_P] = "\n\t\t\t<select name='plugin_mite_" . Mantis2mitePlugin::API_RSRC_P . "_new_time_entry' \n\t\t\t\t\tid='plugin_mite_" . Mantis2mitePlugin::API_RSRC_P . "_new_time_entry'>" . $a_selectBoxesNewTimeEntry[Mantis2mitePlugin::API_RSRC_P] . "</select>";
# wrap the available entries with the HTML select tag
$a_selectBoxesNewTimeEntry[Mantis2mitePlugin::API_RSRC_S] = "\n\t\t\t<select name='plugin_mite_" . Mantis2mitePlugin::API_RSRC_S . "_new_time_entry' \n\t\t\t\t\tid='plugin_mite_" . Mantis2mitePlugin::API_RSRC_S . "_new_time_entry'>" . $a_selectBoxesNewTimeEntry[Mantis2mitePlugin::API_RSRC_S] . "</select>";
if (count($a_projectBindedRsrces[Mantis2mitePlugin::API_RSRC_P]) == 1) {
    # dirty...
    $i_bindedMiteProject_id = current($a_projectBindedRsrces[Mantis2mitePlugin::API_RSRC_P]);
    $i_bindedMiteProject_id = $i_bindedMiteProject_id['mite_project_id'];
    $a_selectBoxesNewTimeEntry[Mantis2mitePlugin::API_RSRC_P] = $a_projectBindedRsrces[Mantis2mitePlugin::API_RSRC_P][$i_bindedMiteProject_id]['name'] . "\n\t\t\t<input type='hidden' name='plugin_mite_projects_new_time_entry' \n\t\t\t\t    value='" . $i_bindedMiteProject_id . "' id='plugin_mite_projects_new_time_entry' />";
}
# add the services select list to the output
###########################################
$s_output .= " \n\t\t<fieldset><legend>" . lang_get('plugin_mite_header_new_time_entry') . "</legend>\n\t\t\t<div class='time_entry_param'>\n\t\t\t\t<label for='plugin_mite_date_new_time_entry'>" . lang_get('plugin_mite_header_date_new_time_entry') . "\n\t\t\t\t</label>\n\t\t\t\t<input type='text' name='plugin_mite_date_new_time_entry'\n\t\t\t\t\t   id='plugin_mite_date_new_time_entry' value='" . date('Y-m-d') . "' />\n\t\t\t\t<span class='plugin_mite_user_input_helper'>\n\t\t\t\t\t<a tabIndex='-1' href='#'>?</a></span>\n\t\t\t\t<span class='plugin_mite_user_input_helper_text' style='display:none'>" . lang_get('plugin_mite_date_help_text') . "</span>\t   \n\t\t\t</div>\n\t\t\t<div class='time_entry_param'>\n\t\t\t\t<label for='plugin_mite_projects_new_time_entry'>" . lang_get('plugin_mite_header_projects_new_time_entry') . "\n\t\t\t\t</label>" . $a_selectBoxesNewTimeEntry[Mantis2mitePlugin::API_RSRC_P] . "\n\t\t\t</div>\n\t\t\t<div class='time_entry_param'>\n\t\t\t\t<label for='plugin_mite_services_new_time_entry'>" . lang_get('plugin_mite_header_services_new_time_entry') . "\n\t\t\t\t</label>" . $a_selectBoxesNewTimeEntry[Mantis2mitePlugin::API_RSRC_S] . "\n\t\t\t</div>\n\t\t\t\n\t\t\t<div class='time_entry_param'>\n\t\t\t\t<label for='plugin_mite_hours_new_time_entry'>" . lang_get('plugin_mite_header_hours_new_time_entry') . "\n\t\t\t\t</label>\n\t\t\t\t<input type='text' name='plugin_mite_hours_new_time_entry' \n\t\t\t\t\t   id='plugin_mite_hours_new_time_entry' value='0:00'/>\n\t\t\t\t<span class='plugin_mite_user_input_helper'>\n\t\t\t\t\t<a tabIndex='-1' href='#'>?</a></span>\n\t\t\t\t<span class='plugin_mite_user_input_helper_text' style='display:none'>" . lang_get('plugin_mite_hours_help_text') . "</span>\n\t\t\t</div>\n\t\t\t<div class='time_entry_param'>\n\t\t\t\t<label for='plugin_mite_note_new_time_entry'>" . lang_get('plugin_mite_header_note_new_time_entry') . "\n\t\t\t\t</label>\n\t\t\t\t<span class='plugin_mite_user_input_helper'>\n\t\t\t\t\t<a tabIndex='-1' href='#'>?</a></span>\n\t\t\t\t<span class='plugin_mite_user_input_helper_text' style='display:none'>" . lang_get('plugin_mite_help_note_pattern') . "</span> \n\t\t\t\t<input type='text' name='plugin_mite_note_new_time_entry' \n\t\t\t\t\t   id='plugin_mite_note_new_time_entry' autocomplete='off' value='" . stripslashes(Mantis2mitePlugin::replacePlaceHolders(current_user_get_field(Mantis2mitePlugin::DB_FIELD_NOTE_PATTERN), $i_bugId)) . "' />\n\t\t\t</div>\n\t\t\t<div class='formularButtons'>\n\t\t\t\t<div class='buttonsRight'>\n\t\t\t\t\t<button type='submit' id='plugin_mite_add_new_time_entry'>" . lang_get('plugin_mite_add_new_time_entry') . "\n\t\t\t\t\t</button>\n\t\t\t\t</div>\n\t\t\t\t<div class='buttonsLeft'>\n\t\t\t\t\t<a href='#' id='plugin_mite_cancel_adding_time_entry'>" . lang_get('plugin_mite_cancel_adding_time_entry') . "\n\t\t\t\t\t</a>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</fieldset>";
echo $s_output;
Пример #2
0
                    }
                    $i_timeInMinutes = $a_timeUnits[0] * 60 + $a_timeUnits[1];
                    break;
                case 'dot':
                case 'comma':
                    $i_timeInMinutes = $a_timeUnits[0] * 60 + round($a_timeUnits[1] / pow(10, strlen($a_timeUnits[1])) * 60);
                    break;
            }
        }
    }
    # build XML request for MITE API
    $s_postRequest = sprintf(" \n\t\t\t<time-entry>\n\t\t\t\t<date-at>%s</date-at>\n\t\t\t\t<minutes>%d</minutes>\n\t\t\t\t<note>%s</note>\n\t\t\t  \t<service-id>%d</service-id>\n\t\t\t  \t<project-id>%d</project-id>\n\t\t\t</time-entry>", Mantis2mitePlugin::mysqlDate($a_data['plugin_mite_date_new_time_entry']), intval($i_timeInMinutes), urldecode($s_note), intval($a_data['plugin_mite_services_new_time_entry']), intval($a_data['plugin_mite_projects_new_time_entry']));
    try {
        $o_responseXml = $o_miteRemote->sendRequest('post', '/time_entries.xml', $s_postRequest);
        # add the time entry to the database
        $s_query = sprintf("\n\t\t        INSERT INTO {$s_tableTimeEntries}\n\t\t\t\t (user_id,bug_id,mite_time_entry_id,mite_project_id,mite_service_id,\n\t\t\t\t  mite_duration,mite_date_at,mite_note,created_at,updated_at)\n\t\t \t\tVALUES (%d, %d, %d, %d, %d, %d, '%s', '%s', '%s', '%s')", auth_get_current_user_id(), intval($a_data['plugin_mite_current_bug']), intval($o_responseXml->id), intval($a_data['plugin_mite_projects_new_time_entry']), intval($a_data['plugin_mite_services_new_time_entry']), $i_timeInMinutes, Mantis2mitePlugin::mysqlDate($o_responseXml->{'date-at'}, true), htmlentities($s_note, ENT_QUOTES, 'UTF-8'), Mantis2mitePlugin::mysqlDate($o_responseXml->{'created-at'}), Mantis2mitePlugin::mysqlDate($o_responseXml->{'created-at'}));
        $r_result = db_query_bound($s_query);
    } catch (Exception $e) {
        # EXIT on function errors
        echo "<error>" . $e->getMessage() . "</error>";
        exit;
    }
} elseif ($_POST['action'] == 'deleteEntry') {
    try {
        $o_miteRemote->sendRequest('delete', '/time_entries/' . $a_data['mite_id'] . ".xml");
    } catch (Exception $e) {
        # EXIT on function errors
        echo "<error>" . $e->getMessage() . "</error>";
    }
    # delete entry from the Mantis database
    $s_query = sprintf(" \n\t         DELETE FROM {$s_tableTimeEntries}\n\t\t\t WHERE mite_time_entry_id = %d AND user_id = %d", $a_data['mite_id'], auth_get_current_user_id());
Пример #3
0
$b_miteConnectionVerified = $b_visibleBtnUnbindConnection = $b_visibleLinkChangeApiKey = $b_visibleLinkChangeAccountName = false;
############
# ACTION
#######
auth_reauthenticate();
html_page_top1(lang_get('plugin_mite_title'));
html_page_top2();
# build config arrays for convenient access to necessary elements
#################################################################
$a_configParams['api_key'] = array('name' => Mantis2mitePlugin::DB_FIELD_API_KEY, 'value' => current_user_get_field(Mantis2mitePlugin::DB_FIELD_API_KEY), 'label' => lang_get('plugin_mite_api_key'), 'type' => 'text', 'readonly' => '', 'cssClass' => '', 'help' => '');
if ($a_configParams['api_key']['value']) {
    $a_configParams['api_key']['value'] = Mantis2mitePlugin::decodeValue($a_configParams['api_key']['value']);
}
$a_configParams['account_name'] = array('name' => Mantis2mitePlugin::DB_FIELD_ACCOUNT_NAME, 'value' => current_user_get_field(Mantis2mitePlugin::DB_FIELD_ACCOUNT_NAME), 'label' => lang_get('plugin_mite_account_name'), 'type' => 'text', 'readonly' => '', 'cssClass' => '', 'help' => '');
if ($a_configParams['account_name']['value']) {
    $a_configParams['account_name']['value'] = Mantis2mitePlugin::decodeValue($a_configParams['account_name']['value']);
}
# get the path to this plugin
$s_pluginDirPath = helper_mantis_url("plugins/" . plugin_get_current() . "/");
# get connection status
$b_miteConnectionVerified = current_user_get_field(Mantis2mitePlugin::DB_FIELD_CONNECT_VERIFIED);
# add options if the connection was verified
############################################
if ($b_miteConnectionVerified) {
    $s_miteConnectionStatus = sprintf(lang_get('plugin_mite_connection_verified'), current_user_get_field(Mantis2mitePlugin::DB_FIELD_CONNECT_LAST_UPDATED));
    $s_connectionStatusCssClass = 'plugin_mite_positive_connection_status';
    $a_configParams['account_name']['readonly'] = $a_configParams['api_key']['readonly'] = " readonly='readonly'";
    $a_configParams['account_name']['cssClass'] = $a_configParams['api_key']['cssClass'] = " class='readonly'";
    $a_configParams['api_key']['type'] = "password";
    $b_visibleBtnUnbindConnection = $b_visibleLinkChangeApiKey = $b_visibleLinkChangeAccountName = true;
    $s_bgUserAccountDataCssClass = 'mite_user_account_active';
            # append the customer name to a project name that belongs to more than one customers
            if ($s_type == Mantis2mitePlugin::API_RSRC_P && count($a_miteProjectNames[$s_entryName]) > 1) {
                $s_entryName .= " (" . $a_miteProjectNames[$s_entryName][$i_idEntryPossiblyModified] . ")";
            }
            $a_logs[$s_type][] = "Updated entry from name='" . $a_tmpEntryMantis['name'] . "' to name='" . $s_entryName . "' " . "on '" . $a_fieldNamesMiteRsrc_id[$s_type] . "=" . $i_idEntryPossiblyModified . "'";
            $a_queries[] = sprintf(" \n\t\t\t\t\tUPDATE " . $s_DBTable_mps . " \n\t\t\t\t\tSET name = '%s', mite_updated_at = '%s'\n\t\t\t\t\tWHERE id = %d", Mantis2mitePlugin::encodeValue($s_entryName), $a_tmpEntryMite['mite_updated_at'], $a_tmpEntryMantis['id']);
        }
    }
}
# execute the database queries
for ($i = 0; $i < count($a_queries); $i++) {
    $r_result = db_query_bound($a_queries[$i]);
}
# set connection verified flag in the database
user_set_field($i_userId, Mantis2mitePlugin::DB_FIELD_CONNECT_VERIFIED, 1);
# update last update value
user_set_field($i_userId, Mantis2mitePlugin::DB_FIELD_CONNECT_LAST_UPDATED, Mantis2mitePlugin::mysqlDate());
# save the account name
user_set_field($i_userId, Mantis2mitePlugin::DB_FIELD_ACCOUNT_NAME, Mantis2mitePlugin::encodeValue($_POST[Mantis2mitePlugin::DB_FIELD_ACCOUNT_NAME]));
# save the API key
user_set_field($i_userId, Mantis2mitePlugin::DB_FIELD_API_KEY, Mantis2mitePlugin::encodeValue($_POST[Mantis2mitePlugin::DB_FIELD_API_KEY]));
# build xml log messages
foreach ($a_logs as $s_type => $a_messages) {
    foreach ($a_messages as $s_message) {
        $s_xmlMsg .= "<message data='" . $s_type . "'>" . $s_message . "</message>";
    }
}
# force re-initialization of session stored user values
session_set('plugin_mite_status_session_vars', 'reinit');
# return xml log messages
echo "<messages datetimestamp='" . date('Y-m-d H:i:s') . "'>" . $s_xmlMsg . "</messages>";