Example #1
0
<?php

if (!empty($_POST)) {
    include_once 'includes/basics/basics.inc';
    $postArray = get_postArray_From_jqSearializedArray($_POST['headerData']);
    if (!empty($postArray['class_name']) && !empty($postArray['program_name'])) {
        $class = $postArray['class_name'][0];
        $program_name = $postArray['program_name'][0];
        $p = new sys_program();
        $p->program_name = $program_name;
        $p->class = $class;
        $p->parameters = serialize($postArray);
        $p->status = 'Initiated';
        $p->audit_trial();
        try {
            $p->save();
            $dbc->confirm();
            echo "<div id='json_save_header'><div class='message'>The program is sucessfully saved; Program Id is " . $p->sys_program_id . '</div></div>';
        } catch (Exception $e) {
            echo " Saving the program failed! " . $e->getMessage();
            return -99;
        }
    }
    return;
}
?>

<?php 
$hideContextMenu = true;
global $s;
if (!empty($_GET['class_name']) && !empty($_GET['program_name'])) {
Example #2
0
<?php

if (!empty($_POST)) {
    include_once 'includes/basics/basics.inc';
    $postArray = get_postArray_From_jqSearializedArray($_POST['headerData']);
    if (!empty($postArray['class_name']) && !empty($postArray['program_name'])) {
        $class = $postArray['class_name'][0];
        $program_name = $postArray['program_name'][0];
        $p = new sys_program();
        $p->program_name = $program_name;
        $p->class = $class;
        $p->parameters = serialize($postArray);
        $p->status = 'Initiated';
        try {
            $p->_before_save($postArray);
            $p->save();
            $dbc->confirm();
            echo "<div id='json_save_header'>";
            echo '<div class="alert alert-success alert-dismissible" role="alert">
   <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
            echo "<div class='message'>The program is sucessfully saved; Program Id is " . $p->sys_program_id . '</div>' . '</div></div>';
        } catch (Exception $e) {
            echo " Saving the program failed! " . $e->getMessage();
            return -99;
        }
    }
    return;
}
$hideContextMenu = true;
global $s;
if (!empty($_GET['class_name']) && !empty($_GET['program_name'])) {
Example #3
0
function start_next_program()
{
    global $dbc, $si;
    $p = new sys_program();
    $p_toStart = $p->findBy_status('Initiated');
    if (!empty($p_toStart)) {
        foreach ($p->field_a as $key => $value) {
            $p->{$value} = $p_toStart->{$value};
        }
        //update the status to inprogress
        $p->status = 'inprogress';
        $p->save();
        $dbc->confirm();
        $class = $p->class;
        ${$class} = new $class();
        if ($p_toStart->request_type == 'REPORT') {
            $search_class_obj_all = ${$class}->findBySql(base64_decode($p_toStart->report_query));
            $search_class_array_all = json_decode(json_encode($search_class_obj_all), true);
            if (!empty($p_toStart->op_email_address)) {
                //send email
                $im = new inomail();
                $im->FromName = $si->site_name;
                $email_a = explode(',', $p_toStart->op_email_address);
                foreach ($email_a as $em_k => $email_v) {
                    $im->addAddress($email_v);
                }
                $im->addReplyTo($si->email, 'Search Output');
                $im->Subject = 'Search Result';
                $im->Body = 'Please find attached the search result';
                switch ($p_toStart->op_email_format) {
                    case 'text_format':
                        $report_op = array2text($search_class_array_all);
                        $file_name = date("Y-m-d") . '_' . $class . '_report_output.txt';
                        break;
                    case 'pdf_format':
                        $report_op = array2pdf($search_class_array_all);
                        $file_name = date("Y-m-d") . '_' . $class . '_report_output.pdf';
                        break;
                    case 'xml_format':
                        $report_op = array2xml($search_class_array_all);
                        $file_name = date("Y-m-d") . '_' . $class . '_report_output.txt';
                        break;
                    case 'worddoc_format':
                        $report_op = array2worddoc($search_class_array_all);
                        $file_name = date("Y-m-d") . '_' . $class . '_report_output.doc';
                        break;
                    default:
                        $report_op = array2csv($search_class_array_all);
                        $file_name = date("Y-m-d") . '_' . $class . '_report_output.csv';
                        break;
                }
                $im->addStringAttachment($report_op, $file_name);
                try {
                    $im->ino_sendMail();
                    $p->message = "Program {$p->program_name} is sucessfully completed <br>" . execution_time();
                    $p->status = 'Completed';
                } catch (Exception $e) {
                    $p->status = 'Error';
                }
                $p->save();
            }
        } else {
            try {
                $result = call_user_func(array(${$class}, $p->program_name), $p->parameters);
                $result_message = is_array($result) ? $result[0] : $result;
                $result_output = is_array($result) ? $result[1] : null;
                $p->message = "Program {$p->program_name} is sucessfully completed <br>" . $result_message . '<br>' . execution_time();
                $p->status = 'Completed';
                try {
                    if (!empty($result_output)) {
                        $op_file_name = $p->program_name . '_' . time() . '.xls';
                        $module_name = $class::$module;
                        $file_path = HOME_DIR . "/files/outputs/modules/{$module_name}/{$p->program_name}/{$op_file_name}";
                        $file = fopen($file_path, 'w');
                        $headerData = [];
                        foreach ($result_output[0] as $key => $value) {
                            array_push($headerData, $key);
                        }
                        fputcsv($file, $headerData);
                        foreach ($result_output as $obj) {
                            $rowData = [];
                            foreach ($obj as $key => $value) {
                                array_push($rowData, $value);
                            }
                            fputcsv($file, $rowData);
                        }
                        fclose($file);
                        $p->output_path = "/files/outputs/modules/{$module_name}/{$p->program_name}/{$op_file_name}";
                    }
                } catch (Exception $e) {
                    $p->output_path = null;
                }
                $p->save();
            } catch (Exception $e) {
                $p->status = 'Failed';
                $p->message = "<br> Program failed @ start_program " . __LINE__ . '<br>' . $e->getMessage();
                $p->save();
            }
        }
        $dbc->confirm();
    } else {
        sleep(5);
    }
    execution_time();
    unset($p_toStart);
    unset($p);
}
function start_next_program()
{
    global $dbc;
    $prg_schedule = new sys_program_schedule();
    $all_prg_schedule = $prg_schedule->findAll();
    /*
     * Foreach schedule check the schedule frequency
     * Check if any program is submitted with in the schduled ferquency, If yes, continue. Else create a new program
     */
    $curr_time = new DateTime();
    foreach ($all_prg_schedule as $prg_schedule) {
        $intvl = 'P365D';
        switch ($prg_schedule->frequency_uom) {
            case 'MINUTELY':
                $intvl_i = $prg_schedule->frequency_value;
                $intvl = 'PT' . $intvl_i . 'M';
                break;
            case 'HOURLY':
                $intvl_i = $prg_schedule->frequency_value;
                $intvl = 'PT' . $intvl_i . 'H';
                break;
            case 'DAILY':
                $intvl_i = $prg_schedule->frequency_value;
                $intvl = 'P' . $intvl_i . 'D';
                break;
            case 'WEEKLY':
                $intvl_i = $prg_schedule->frequency_value * 7;
                $intvl = 'P' . $intvl_i . 'D';
                break;
            case 'MONTHLY':
                $intvl_i = $prg_schedule->frequency_value;
                $intvl = 'P' . $intvl_i . 'M';
                break;
        }
        $date_time_int = new DateInterval($intvl);
        $curr_time->sub($date_time_int);
        $sys_prg = new sys_program();
        $sys_prg->class = $prg_schedule->program_class_name;
        $sys_prg->program_name = $prg_schedule->program_name;
        $sys_prg->program_source = 'SCHEDULER';
        $sys_prg->request_type = $prg_schedule->request_type;
        $sys_prg->report_query = $prg_schedule->report_query;
        $sys_prg->op_email_address = $prg_schedule->op_email_address;
        $sys_prg->op_email_format = $prg_schedule->op_email_format;
        $sys_prg->creation_date = $curr_time->format('Y-m-d');
        $existing_schl = $sys_prg->findBy_schdule_details();
        if ($existing_schl) {
            continue;
        } else {
            //submit a request
            $all_parameters = unserialize($prg_schedule->parameter);
            if ($prg_schedule->increase_date_parameter_cb) {
                $format_param = 'Y-m-d';
                foreach ($all_parameters as $param_k => &$param_v) {
                    $d = DateTime::createFromFormat($format_param, $param_v[0]);
                    if ($d && $d->format($format_param) == $param_v[0]) {
                        $scheduled_date_time = new DateTime($prg_schedule->creation_date);
                        $param_date_time = new DateTime($param_v[0]);
                        $param_date_time->diff($scheduled_date_time, true);
                        $diff = $param_date_time->diff($scheduled_date_time);
                        $param_d = new DateTime();
                        if ($diff->invert) {
                            //negative - use add
                            $param_d->add(new DateInterval('P' . $diff->days . 'D'));
                        } else {
                            //positive - use sub
                            $param_d->sub(new DateInterval('P' . $diff->days . 'D'));
                        }
                        $param_v[0] = $param_d->format($format_param);
                    }
                }
            }
            $sys_prg->parameters = serialize($all_parameters);
            $sys_prg->description = 'Auto schdule program @' . $curr_time->format('Y-m-d');
            $sys_prg->status = 'Initiated';
            $sys_prg->save();
        }
    }
    $dbc->confirm();
    sleep(15);
    execution_time();
}