<?php

if ($ubillingConfig->getAlterParam('DEALWITHIT_ENABLED')) {
    if (cfr('DEALWITHIT')) {
        $dealWithIt = new DealWithIt();

        if (wf_CheckGet(array('username'))) {
            $login = $_GET['username'];
            //creating new task
            if (wf_CheckPost(array('newschedlogin'))) {
                $createResult = $dealWithIt->catchCreateRequest();
                if ($createResult) {
                    show_error($createResult);
                } else {
                    rcms_redirect(DealWithIt::URL_ME . '&username=' . $login);
                }
            }
            //deleting existing task
            if (wf_CheckGet(array('deletetaskid'))) {
                $dealWithIt->deleteTask($_GET['deletetaskid']);
                rcms_redirect(DealWithIt::URL_ME . '&username=' . $login);
            }
            //displaying interface parts
            show_window(__('Create new task'), $dealWithIt->renderCreateForm($login));
            //json reply
            if (wf_CheckGet(array('ajax'))) {
                $dealWithIt->AjaxDataTasksList($login);
            }
            show_window(__('Held jobs for this user'), $dealWithIt->renderTasksListAjax($login));

            show_window('', web_UserControls($login));
        } elseif (wf_CheckPost(array('newschedloginsarr'))) {
            $createMassResult = $dealWithIt->catchCreateMassRequest();
            if ($createMassResult) {
                show_error($createMassResult);
                $dealWithIt->renderDealWithItControl();
            } else {
                rcms_redirect('?module=report_dealwithit');
            }
        } else {
            if (wf_CheckGet(array('ajinput'))) {
                $dealWithIt->catchAjRequest();
            } else {
                $dealWithIt->renderDealWithItControl();
            }
        }
    } else {
        show_error(__('Access denied'));
    }
} else {
    show_error(__('This module is disabled'));
}
?>
