Пример #1
0
/** expecting host name as $in_hostname
 *
 * processes a host array and sends to the hostdetails.php page
 */
function process_host_detail($in_hostname)
{
    global $NagiosData;
    global $NagiosUser;
    $hd = $NagiosData->get_details_by('host', $in_hostname);
    $hostname = $hd['host_name'];
    if (!$NagiosUser->is_authorized_for_host($hostname)) {
        return false;
    }
    //bail if not authorized
    $duration = calculate_duration($hd['last_state_change']);
    $current_state = return_host_state($hd['current_state']);
    $statetype = return_state_type($hd['state_type']);
    //calculate state
    $current_check = $hd['current_attempt'] . ' of ' . $hd['max_attempts'];
    $date_format = 'M d H:i\\:s\\s Y';
    $last_check = date($date_format, $hd['last_check']);
    $next_check = date($date_format, $hd['next_check']);
    $last_state_change = date($date_format, $hd['last_state_change']);
    if ($hd['last_notification'] == 0) {
        $last_notification = 'Never';
    } else {
        $last_notification = date($date_format, $hd['last_notification']);
    }
    $check_type = $hd['check_type'] == 0 ? 'Active' : 'Passive';
    $check_latency = $hd['check_latency'] . ' seconds';
    $execution_time = $hd['check_execution_time'] . ' seconds';
    $state_change = $hd['percent_state_change'] . '%';
    $membership = check_membership($hostname);
    $state = return_host_state($hd['current_state']);
    //host attributes
    //if else statements generate links for Nagios core commands based on status
    $active_checks = return_enabled($hd['active_checks_enabled']);
    if ($active_checks == 'Enabled') {
        $cmd_active_checks = core_function_link('DISABLE_HOST_CHECK', $hostname);
    } else {
        $cmd_active_checks = core_function_link('ENABLE_HOST_CHECK', $hostname);
    }
    $passive_checks = return_enabled($hd['passive_checks_enabled']);
    if ($passive_checks == 'Enabled') {
        $cmd_passive_checks = core_function_link('DISABLE_PASSIVE_HOST_CHECKS', $hostname);
    } else {
        $cmd_passive_checks = core_function_link('ENABLE_PASSIVE_HOST_CHECKS', $hostname);
    }
    $notifications = return_enabled($hd['notifications_enabled']);
    if ($notifications == 'Enabled') {
        $cmd_notifications = core_function_link('DISABLE_HOST_NOTIFICATIONS', $hostname);
    } else {
        $cmd_notifications = core_function_link('ENABLE_HOST_NOTIFICATIONS', $hostname);
    }
    $flap_detection = return_enabled($hd['flap_detection_enabled']);
    if ($flap_detection == 'Enabled') {
        $cmd_flap_detection = core_function_link('DISABLE_HOST_FLAP_DETECTION', $hostname);
    } else {
        $cmd_flap_detection = core_function_link('ENABLE_HOST_FLAP_DETECTION', $hostname);
    }
    $process_perf_data = return_enabled($hd['process_performance_data']);
    $obsession = return_enabled($hd['obsess_over_host']);
    if ($obsession == 'Enabled') {
        $cmd_obsession = core_function_link('STOP_OBSESSING_OVER_HOST', $hostname);
    } else {
        $cmd_obsession = core_function_link('START_OBSESSING_OVER_HOST', $hostname);
    }
    $add_comment = core_function_link('ADD_HOST_COMMENT', $hostname);
    if ($hd['problem_has_been_acknowledged'] == 0) {
        $cmd_acknowledge = core_function_link('ACKNOWLEDGE_HOST_PROBLEM', $hostname);
        $ack_title = 'Acknowledge Problem';
    } else {
        $cmd_acknowledge = core_function_link('REMOVE_HOST_ACKNOWLEDGEMENT', $hostname);
        $ack_title = 'Remove Acknowledgement';
    }
    $cmd_custom_notification = core_function_link('SEND_CUSTOM_HOST_NOTIFICATION', $hostname);
    $cmd_schedule_downtime = core_function_link('SCHEDULE_HOST_DOWNTIME', $hostname);
    $cmd_schedule_dt_all = core_function_link('SCHEDULE_HOST_SVC_DOWNTIME', $hostname);
    $cmd_schedule_checks = core_function_link('SCHEDULE_HOST_SVC_CHECKS', $hostname);
    $cmd_map = CORECGI . 'statusmap.cgi?host=' . $hostname;
    $core_link = CORECGI . 'extinfo.cgi?type=1&host=' . $hostname;
    $details = array('Host' => $hostname, 'MemberOf' => $membership, 'StatusInformation' => $hd['plugin_output'], 'State' => $current_state, 'Duration' => $duration, 'StateType' => $statetype, 'CurrentCheck' => $current_check, 'LastCheck' => $last_check, 'NextCheck' => $next_check, 'LastStateChange' => $last_state_change, 'LastNotification' => $last_notification, 'CheckType' => $check_type, 'CheckLatency' => $check_latency, 'ExecutionTime' => $execution_time, 'StateChange' => $state_change, 'PerformanceData' => $hd['performance_data'], 'ActiveChecks' => $active_checks, 'PassiveChecks' => $passive_checks, 'Notifications' => $notifications, 'FlapDetection' => $flap_detection, 'ProcessPerformanceData' => $process_perf_data, 'Obsession' => $obsession, 'AddComment' => htmlentities($add_comment), 'MapHost' => htmlentities($cmd_map), 'CmdActiveChecks' => htmlentities($cmd_active_checks), 'CmdPassiveChecks' => htmlentities($cmd_passive_checks), 'CmdNotifications' => htmlentities($cmd_notifications), 'CmdFlapDetection' => htmlentities($cmd_flap_detection), 'CmdObsession' => htmlentities($cmd_obsession), 'CmdAcknowledge' => htmlentities($cmd_acknowledge), 'CmdCustomNotification' => htmlentities($cmd_custom_notification), 'CmdScheduleDowntime' => htmlentities($cmd_schedule_downtime), 'CmdScheduleDowntimeAll' => htmlentities($cmd_schedule_dt_all), 'CmdScheduleChecks' => htmlentities($cmd_schedule_checks), 'AckTitle' => $ack_title, 'CoreLink' => htmlentities($core_link));
    return $details;
}
Пример #2
0
function page_result()
{
    global $site;
    if (!isset($_SESSION['log']) || !file_exists($site['dir'] . '/log/' . $_SESSION['log'])) {
        redirect();
    } else {
        $log = read_log();
    }
    if (empty($log['completed'])) {
        redirect();
    }
    $total_seconds = $log['end'] - $log['start'];
    $time_spent = calculate_duration($total_seconds);
    $total_questions = count($log['questions']);
    $total_correct = 0;
    $total_incorrect = 0;
    foreach ($log['questions'] as $question) {
        if ($question['question']['meaning'] == $question['answer']) {
            $total_correct++;
        } else {
            $total_incorrect++;
        }
    }
    $success_rate = min(array(round($total_correct * 100 / $total_questions), 100));
    $messages = array(95 => array('Excellent!', 'You have answered all of the questions correctly. You seem to have mastered first grade Kanji. Now on to the next level. Good luck!'), 75 => array('Great job!', 'You have answered most of the questions correctly. You seem to have a solid knowledge of first grade Kanji but make sure you review your incorrect answers.'), 50 => array('Good try...', 'Your knowledge of first grade Kanji is just above average. Make sure to carefully review your incorrect answers. You may want to go over your study materials as well.'), 25 => array('Not bad...', 'Your knowledge of first grade Kanji is below the average. It would be a really good idea to review your study materials.'), -1 => array('Oops!', 'You could not answer most of the questions correctly. Make sure to review your study materials and take the test again.'));
    foreach ($messages as $limit => $message) {
        if ($success_rate > $limit) {
            $feedback = $message;
            break;
        }
    }
    echo '
			<h2><span>', $feedback[0], '</span></h2>
			<p>', $feedback[1], '</p>
			<h2><span>Summary</span></h2>
			<dl>
				<dt>Number of questions:</dt>
				<dd>', $total_questions, '</dd>
				<dt>Number of correct answers:</dt>
				<dd>', $total_correct, '</dd>
				<dt>Number of incorrect answers:</dt>
				<dd>', $total_incorrect, '</dd>
				<dt>Success rate:</dt>
				<dd>%', $success_rate, '</dd>
				<dt>Time spent:</dt>
				<dd>', $time_spent, '</dd>
			</dl>
			<h2><span>Review</span></h2>
			<p>You can review your answers clicking on the questions below. The alternative marked with green is the correct answer, whereas the one marked with red is the alternative you have chosen for the incorrect answers. The time you spent on the question is given next to the question number as well.</p>';
    foreach ($log['questions'] as $number => $question) {
        echo '
			<h3><a href="#review_', $number, '" onclick="toggle_question(', $number, '); return false;">Question ', $number, '</a> - ', $question['question']['meaning'] == $question['answer'] ? '<span class="correct">[correct]</span>' : '<span class="incorrect">[incorrect]</span>', ' - (', calculate_duration($question['end'] - $question['start']), ')</h3>
			<div id="review_', $number, '" style="display: none;" class="review">
				<div>', $question['question']['parsed'], '</div>
				<ul>';
        foreach ($question['options'] as $option) {
            $class = '';
            if ($option['meaning'] == $question['answer']) {
                $class = 'incorrect';
            }
            if ($option['meaning'] == $question['question']['meaning']) {
                $class = 'correct';
            }
            echo '
					<li><span class="', $class, '">', $option['meaning'], ' (', $option['parsed'], ')</span></li>';
        }
        echo '
				</ul>
			</div>';
    }
    echo '
			<script type="text/javascript"><!-- // --><![CDATA[
				function toggle_question(item)
				{
					var review_item = document.getElementById("review_" + item);
					review_item.style.display = review_item.style.display == "" ? "none" : "";
				}
			// ]]></script>';
}
Пример #3
0
} else {
    echo $string['unidirectional'] . ' <img src="../artwork/tooltip_icon.gif" class="help_tip" title="' . $string['tooltip_unidirectional'] . '" />';
}
echo '</td></tr>';
if ($test_type < 3) {
    echo '<tr><td class="f">' . $string['marks'] . '</td>';
    echo '<td colspan="3">' . $total_marks;
    if ($marking == 1) {
        echo ' (' . $string['adjusted'] . ' ' . number_format($total_random_mark, 2, '.', ',') . ')';
        echo ' <img src="../artwork/tooltip_icon.gif" class="help_tip" title="' . $string['tooltip_adjustmark'] . '" />';
    }
    echo '</td></tr>';
}
echo "<tr><td class=\"f\"><nobr>&nbsp;" . $string['currentuser'] . "</nobr></td><td>{$person}</td>";
if ($exam_duration) {
    $duration_mins = calculate_duration($exam_duration, $extra_time_mins, $special_needs_percentage);
    echo '<td class="f">' . $string['duration'] . '</td><td>' . StringUtils::nice_duration($duration_mins, $string) . '</td>';
} else {
    echo '<td></td><td></td>';
}
echo '</tr>';
if ($display_remaining_time === true) {
    ?>
    <tr>
       <td></td>
       <td></td>
       <td class="f"><?php 
    echo $string['timeremaining'];
    ?>
</td>
       <?php 
Пример #4
0
    public static function get_arrear_document($staff_id, $pay_year, $pay_month)
    {
        for ($t = $_POST['from_pay_year']; $t < $_POST['to_pay_year'] + 1; $t++) {
            $retCoef = 1;
            $qry = " select max(arrear_ver) MV\r\n\t\t\t\t\tfrom  corrective_payment_writs \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . "\r\n\t\t       ";
            $MaxVer = PdoDataAccess::runquery($qry);
            if (count($MaxVer) == 0 || $MaxVer[0]['MV'] == 0) {
                continue;
            }
            $qry = " select  cpw.staff_id , cpw.writ_id ,  cpw.writ_ver , cpw.arrear_ver , w.execute_date, w.send_letter_no , w.salary_pay_proc\r\n\t\t\r\n\t\t\t\t from corrective_payment_writs cpw inner join  writs w \r\n\t\t\t                                         on cpw.staff_id = w.staff_id and \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcpw.writ_id = w.writ_id and \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcpw.writ_ver = w.writ_ver \r\n\r\n\t\t\t where cpw.pay_year = " . $t . " and cpw.staff_id = " . $SID . " and arrear_ver = " . $MaxVer[0]['MV'] . " and cpw.pay_month = 12 \r\n\t\t\t order by  w.execute_date ";
            $res1 = PdoDataAccess::runquery($qry);
            //............................. پیدا کردن آخرین ماهی که فیش حقوقی در آن محاسبه شده است ................
            $qry = " select max(pay_month) PM from payment_writs where staff_id = " . $SID . " AND pay_year= " . $t;
            $MaxMonth = PdoDataAccess::runquery($qry);
            if ($MaxMonth[0]['PM'] > 0 && $MaxMonth[0]['PM'] < 7) {
                $LastDate = $t . "/" . $MaxMonth[0]['PM'] . "/31";
            } else {
                if ($MaxMonth[0]['PM'] > 6 && $MaxMonth[0]['PM'] < 12) {
                    $LastDate = $t . "/" . $MaxMonth[0]['PM'] . "/30";
                } else {
                    if ($MaxMonth[0]['PM'] == 12) {
                        $LastDate = $t . "/" . $MaxMonth[0]['PM'] . "/29";
                    } else {
                        $LastDate = '0000-00-00';
                    }
                }
            }
            $LAST_PAY_DATE = date('Y-m-d', strtotime(DateModules::shamsi_to_miladi($LastDate) . "+1 days"));
            $LAST_PAY_DATE = DateModules::miladi_to_shamsi($LAST_PAY_DATE);
            if ($res1[count($res1) - 1]['salary_pay_proc'] == 1) {
                $LastDate = DateModules::miladi_to_shamsi($res1[count($res1) - 1]['execute_date']);
                $arr = preg_split('/\\//', $LastDate);
                $NewDate = date('Y-m-d', strtotime(DateModules::shamsi_to_miladi($LastDate) . "-1 days"));
                $LastDate = DateModules::miladi_to_shamsi($NewDate);
                $arr = preg_split('/\\//', $LastDate);
            }
            $LD = array();
            //.................................................................................................
            for ($i = 0; $i < count($res1); $i++) {
                if ($LastDate != '0000-00-00' && DateModules::CompareDate($res1[$i]['execute_date'], str_replace("/", "-", DateModules::shamsi_to_miladi($LastDate))) >= 0) {
                    $LD[$t]['lastDate'] = $LastDate;
                    break;
                }
                $CDate = DateModules::miladi_to_shamsi($res1[$i]['execute_date']);
                $arr2 = preg_split('/\\//', $CDate);
                if (intval($arr2[1]) <= intval($MaxMonth[0]['PM'])) {
                    $qry = " select t.staff_id,max_execute_date ,SUBSTRING(max_execute_date,1,10) execute_date ,\r\n\t\t\t\t\t\tSUBSTRING_INDEX(SUBSTRING(max_execute_date,11),'.',1) writ_id,\r\n\t\t\t\t\t\tSUBSTRING_INDEX(max_execute_date,'.',-1) writ_ver\r\n\r\n\t\t\t\t\tfrom (\r\n\t\t\t\t\t\t\tselect w.staff_id,max( CONCAT(w.execute_date,w.writ_id,'.',w.writ_ver) ) max_execute_date\r\n\r\n\t\t\t\t\t\t\tfrom payment_writs cpw inner join  writs w\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ton  cpw.staff_id = w.staff_id and\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcpw.writ_id = w.writ_id and\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcpw.writ_ver = w.writ_ver\r\n\t\t\t\t\t\t\twhere cpw.pay_year = " . $t . " and cpw.staff_id = " . $SID . " and\r\n\t\t\t\t\t\t\t      /*cpw.pay_month = 12 and*/ execute_date <= '" . $res1[$i]['execute_date'] . "'\r\n\r\n\t\t\t\t\t\t\tgroup by w.staff_id\r\n\t\t\t\t\t\t) t\r\n\t\t\t\t\t\t\t";
                    // پرس و جو بالا هم بایستی union شود با ورژن های قبلی پرداخت تا احکام آنها هم دیده شود .
                    $res2 = PdoDataAccess::runquery($qry);
                    if (count($res2) == 0) {
                        $res2[0]['execute_date'] = '0000-00-00';
                        $res2[0]['writ_id'] = 0;
                        $res2[0]['writ_ver'] = 0;
                    }
                } else {
                    $res2[0]['execute_date'] = '0000-00-00';
                    $res2[0]['writ_id'] = 0;
                    $res2[0]['writ_ver'] = 0;
                }
                /* PdoDataAccess::runquery(" insert compare_arrear_writs (staff_id ,current_execute_date , current_writ_id , current_writ_ver, 
                															   prev_execute_date , prev_writ_id , prev_writ_ver , arrear_ver , pay_year ) values 
                															  (" . $res1[$i]['staff_id'] . ",'" . $res1[$i]['execute_date'] . "'," . $res1[$i]['writ_id'] . "," .
                                    $res1[$i]['writ_ver'] . ",'" . $res2[0]['execute_date'] . "'," . $res2[0]['writ_id'] . "," .
                                    $res2[0]['writ_ver'] . "," . $res1[$i]['arrear_ver'] . "," . $t . " ) ");
                			*/
                if ($res1[$i]['writ_id'] == $res2[0]['writ_id'] && $res1[$i]['writ_ver'] == $res2[0]['writ_ver']) {
                    continue;
                }
                $writNo++;
            }
            //..................اگر برج 12 در دیون محاسبه می شود ولی در قبلی نبوده است بایستی به جدول compare افزوده شود..............................
            /*   if ($res1[(count($res1) - 1)]['salary_pay_proc'] != 1 && $MaxMonth[0]['PM'] < 12) {
            
            
            
                        $qry = " select staff_id , execute_date , writ_id , writ_ver 
                            from writs 
                             where  staff_id = " . $SID . " and salary_pay_proc = 1 and 
                                    execute_date >= '" . DateModules::shamsi_to_miladi($t . '/01/01') . "' and 
                                    execute_date <= '" . DateModules::shamsi_to_miladi($t . '/12/29') . "' and 
                                    issue_date >= '" . $res1[$i - 1]['execute_date'] . "' and state = 3 ";
            
                        $res3 = PdoDataAccess::runquery($qry);
            
                        PdoDataAccess::runquery(" insert compare_arrear_writs ( staff_id ,current_execute_date , current_writ_id , current_writ_ver, 
                                                                    prev_execute_date , prev_writ_id , prev_writ_ver , arrear_ver , pay_year ) values 
                                                                  (" . $SID . ",'" . $res1[$i - 1]['execute_date'] . "'," . $res1[$i - 1]['writ_id'] . "," .
                                $res1[$i - 1]['writ_ver'] . ",'" . $res3[0]['execute_date'] . "'," . $res3[0]['writ_id'] . "," .
                                $res3[0]['writ_ver'] . "," . $res1[$i - 1]['arrear_ver'] . "," . $t . " ) ");
                    } */
            //....................we need this part......................
            $res = PdoDataAccess::runquery(" select * \r\n\t\t\t\t\t\t\t\t\t\tfrom compare_arrear_writs \r\n\t\t\t\t\t\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year =" . $t . " and arrear_ver = " . $MaxVer[0]['MV']);
            for ($i = 0; $i < count($res); $i++) {
                $writsWhereClause .= ' (wsi.writ_id=' . $res[$i]['current_writ_id'] . ' AND wsi.writ_ver=' . $res[$i]['current_writ_ver'] . ' AND wsi.staff_id=' . $res[$i]['staff_id'] . ') OR 
							 (wsi.writ_id=' . $res[$i]['prev_writ_id'] . ' AND wsi.writ_ver=' . $res[$i]['prev_writ_ver'] . ' AND wsi.staff_id=' . $res[$i]['staff_id'] . ' ) OR  ';
                $PrewritsWhereClause .= ' (wsi.writ_id=' . $res[$i]['prev_writ_id'] . ' AND wsi.writ_ver=' . $res[$i]['prev_writ_ver'] . ' AND wsi.staff_id=' . $res[$i]['staff_id'] . ' ) OR  ';
                $CurrwritsWhereClause .= ' (wsi.writ_id=' . $res[$i]['current_writ_id'] . ' AND wsi.writ_ver=' . $res[$i]['current_writ_ver'] . ' AND wsi.staff_id=' . $res[$i]['staff_id'] . ') OR ';
            }
            //.............................................................
        }
        $writsWhereClause = substr($writsWhereClause, 0, strlen($writsWhereClause) - 4);
        $PrewritsWhereClause = substr($PrewritsWhereClause, 0, strlen($PrewritsWhereClause) - 4);
        $CurrwritsWhereClause = substr($CurrwritsWhereClause, 0, strlen($CurrwritsWhereClause) - 4);
        $ResITM2 = PdoDataAccess::runquery(" select distinct wsi.salary_item_type_id  , sit.print_title ,sit.month_length_effect\r\n\t\t\t\t\t\t\t\t\t\t\t from writ_salary_items wsi \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join salary_item_types sit \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ton  wsi.salary_item_type_id  = sit.salary_item_type_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\twhere " . $writsWhereClause);
        //..............................................................................
        $ResITM = array();
        $diffVal = 0;
        for ($j = 0; $j < count($ResITM2); $j++) {
            $res6 = PdoDataAccess::runquery(" select wsi.salary_item_type_id , sit.print_title , sum(wsi.value) CurrVal \r\n\t\t\t\t\t\t\t\t\t\t\t from writ_salary_items wsi \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join salary_item_types sit \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ton  wsi.salary_item_type_id  = sit.salary_item_type_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\twhere wsi.must_pay = 1 and (" . $CurrwritsWhereClause . ") and wsi.salary_item_type_id =" . $ResITM2[$j]['salary_item_type_id']);
            $res7 = PdoDataAccess::runquery(" select wsi.salary_item_type_id , sit.print_title , sum(wsi.value) PreVal \r\n\t\t\t\t\t\t\t\t\t\t\t from writ_salary_items wsi \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join salary_item_types sit \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ton  wsi.salary_item_type_id  = sit.salary_item_type_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\twhere  wsi.must_pay = 1 and (" . $PrewritsWhereClause . ") and wsi.salary_item_type_id =" . $ResITM2[$j]['salary_item_type_id']);
            $diffVal = $res6[0]['CurrVal'] - $res7[0]['PreVal'];
            if ($diffVal != 0) {
                $diffVal = 0;
                $ResITM[] = array('salary_item_type_id' => $ResITM2[$j]['salary_item_type_id'], 'print_title' => $ResITM2[$j]['print_title'], 'month_length_effect' => $ResITM2[$j]['month_length_effect']);
            } else {
                //.................................... چنانچه قلمی در حکم فعلی حذف شده باشد.................
                for ($i = 0; $i < count($res); $i++) {
                    $res6 = PdoDataAccess::runquery(' select wsi.salary_item_type_id , sit.print_title , sum(wsi.value) CurrVal 
                                                        from writ_salary_items wsi 
                                                                    inner join salary_item_types sit 
                                                                                    on  wsi.salary_item_type_id  = sit.salary_item_type_id
                                                                    where wsi.must_pay = 1 and 
                                                                         (wsi.writ_id=' . $res[$i]['prev_writ_id'] . ' AND 
                                                                          wsi.writ_ver=' . $res[$i]['prev_writ_ver'] . ' AND
                                                                          wsi.staff_id=' . $res[$i]['staff_id'] . ' ) and 
                                                                          wsi.salary_item_type_id =' . $ResITM2[$j]['salary_item_type_id']);
                    $res7 = PdoDataAccess::runquery(' select wsi.salary_item_type_id , sit.print_title , sum(wsi.value) PreVal 
                                                        from writ_salary_items wsi 
                                                                inner join salary_item_types sit 
                                                                        on  wsi.salary_item_type_id  = sit.salary_item_type_id
                                                        where  wsi.must_pay = 1 and 
                                                              (wsi.writ_id=' . $res[$i]['current_writ_id'] . ' AND 
                                                               wsi.writ_ver=' . $res[$i]['current_writ_ver'] . ' AND 
                                                               wsi.staff_id=' . $res[$i]['staff_id'] . ') and 
                                                               wsi.salary_item_type_id =' . $ResITM2[$j]['salary_item_type_id']);
                    if (count($res6) != count($res7) || $res6[0]['CurrVal'] != $res7[0]['PreVal']) {
                        if (!in_array($ResITM2[$j]['salary_item_type_id'], $ResITM)) {
                            $ResITM[] = array('salary_item_type_id' => $ResITM2[$j]['salary_item_type_id'], 'print_title' => $ResITM2[$j]['print_title'], 'month_length_effect' => $ResITM2[$j]['month_length_effect']);
                        }
                    }
                }
            }
        }
        //..........................................................................
        $TotalsumDiff = $TotalMainVal = $TotalRowTax = $TotalRowIns = $TotalRowRet = $TotalPay = 0;
        for ($t = $_POST['from_pay_year']; $t < $_POST['to_pay_year'] + 1; $t++) {
            $retCoef = 1;
            $qry = " select max(arrear_ver) MV\r\n\t\t\t\t\tfrom  corrective_payment_writs \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . "\r\n\t\t       ";
            $MaxVer = PdoDataAccess::runquery($qry);
            if (count($MaxVer) == 0 || $MaxVer[0]['MV'] == 0) {
                continue;
            }
            $res = PdoDataAccess::runquery(" select * \r\n\t\t\t\t\t\t\t\t\t\tfrom compare_arrear_writs \r\n\t\t\t\t\t\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year =" . $t . " and arrear_ver = " . $MaxVer[0]['MV']);
            $prior_execute_date = $current_execute_date = $prior_writ_type = $current_writ_type = '';
            $current_writ_items = $prior_writ_items = array();
            $sdate = "";
            for ($i = 0; $i < count($res); $i++) {
                if ($res[$i]['current_writ_id'] == $res[$i]['prev_writ_id'] && $res[$i]['current_writ_ver'] == $res[$i]['prev_writ_ver']) {
                    continue;
                }
                if (!empty($LD[$t]['lastDate'])) {
                    $toDate = $LD[$t]['lastDate'];
                } else {
                    if ($LastDate == '0000-00-00') {
                        $toDate = $t . "/12/30";
                    } else {
                        $toDate = DateModules::CompareDate(str_replace("/", "-", DateModules::shamsi_to_miladi($t . "/12/30")), str_replace("/", "-", DateModules::shamsi_to_miladi($LastDate))) >= 0 ? $LastDate : $t . "/12/30";
                    }
                }
                /* if ($sdate != "" && $sdate > '0000-00-00')
                       $Row .= "<td>" . $sdate . "</td>";
                   else
                       $Row .= "<td>" .DateModules::miladi_to_shamsi($res[$i]['current_execute_date']). "</td>";
                   */
                if ($res[$i]['current_execute_date'] == $res[$i + 1]['current_execute_date']) {
                    //$Row .= "<td>" . DateModules::AddToJDate($toDate, 1) . "</td>";
                    $sdate = DateModules::AddToJDate($toDate, 1);
                }
                /*else if ($sdate != "" && $sdate > '0000-00-00' && empty($res[$i + 1]['current_execute_date']))
                                $Row .= "<td>" . $t . "/12/29" . "</td>";
                            elseif($res[$i + 1]['current_execute_date'] !='0000-00-00' && DateModules::CompareDate(DateModules::miladi_to_shamsi($res[$i + 1]['current_execute_date']),$LAST_PAY_DATE) == 1  )
                            {
                                  $Row .= "<td>" . $LAST_PAY_DATE . "</td>";
                                
                            }
                            else
                                $Row .= "<td>" . ( empty($res[$i + 1]['current_execute_date']) ? $toDate : DateModules::miladi_to_shamsi($res[$i + 1]['current_execute_date']) ) . "</td>";
                */
                if (!empty($LD[$t]['lastDate'])) {
                    $toDate2 = DateModules::shamsi_to_miladi(DateModules::AddToJDate($LD[$t]['lastDate'], 1));
                } else {
                    if ($LastDate == '0000-00-00') {
                        $toDate2 = DateModules::shamsi_to_miladi($t + 1 . "/01/01");
                    } else {
                        $toDate2 = DateModules::CompareDate(str_replace("/", "-", DateModules::shamsi_to_miladi($t . "/12/30")), str_replace("/", "-", DateModules::shamsi_to_miladi($LastDate))) >= 0 ? DateModules::AddToJDate($LastDate, 1) : DateModules::shamsi_to_miladi($t + 1 . "/01/01");
                    }
                }
                $endDate = empty($res[$i + 1]['current_execute_date']) ? $toDate2 : $res[$i + 1]['current_execute_date'];
                if ($res[$i]['current_execute_date'] == $res[$i + 1]['current_execute_date']) {
                    $endDate = $toDate2;
                }
                if ($sdate != "" && $sdate > '0000-00-00' && empty($res[$i + 1]['current_execute_date'])) {
                    $endDate = $t + 1 . "/1/01";
                    if ($resPerInfo[0]['person_type'] == 3) {
                        $DayNo = round(DateModules::GDateMinusGDate(DateModules::shamsi_to_miladi($endDate), DateModules::shamsi_to_miladi($sdate)));
                        $DayNo2 = calculate_duration($sdate, $endDate);
                    } else {
                        $DayNo = calculate_duration($sdate, $endDate);
                    }
                } else {
                    if ($resPerInfo[0]['person_type'] == 3) {
                        $DayNo = round(DateModules::GDateMinusGDate(DateModules::shamsi_to_miladi($endDate), $res[$i]['current_execute_date']));
                        $DayNo2 = calculate_duration($res[$i]['current_execute_date'], $endDate);
                    } else {
                        $DayNo = calculate_duration($res[$i]['current_execute_date'], $endDate);
                    }
                }
                if ($res[$i + 1]['current_execute_date'] != '0000-00-00' && DateModules::CompareDate(DateModules::miladi_to_shamsi($res[$i + 1]['current_execute_date']), $LAST_PAY_DATE) == 1) {
                    $DayNo = calculate_duration($res[$i]['current_execute_date'], DateModules::shamsi_to_miladi($LAST_PAY_DATE));
                }
                // $Row .= "<td>" . $DayNo . "</td>";
                $sumDiff = $MainVal = 0;
                $RetInc = $TaxInc = $InsInc = 0;
                for ($j = 0; $j < count($ResITM); $j++) {
                    $val1 = get_writSalaryItem_value($res[$i]["current_writ_id"], $res[$i]["current_writ_ver"], $res[$i]["staff_id"], $ResITM[$j]["salary_item_type_id"]);
                    $val2 = get_writSalaryItem_value($res[$i]["prev_writ_id"], $res[$i]["prev_writ_ver"], $res[$i]["staff_id"], $ResITM[$j]["salary_item_type_id"]);
                    $RetRes = PdoDataAccess::runquery(" select retired_include , tax_include , insure_include \r\n                                                      from salary_item_types where salary_item_type_id = " . $ResITM[$j]["salary_item_type_id"]);
                    //  $Row .= "<td>" . CurrencyModulesclass::toCurrency($val1 - $val2) . (($val1 - $val2) < 0 ? "-&nbsp;" : "" ) . "</td>";
                    $sumDiff += $val1 - $val2;
                    if (empty($Itm[$j]['sumVal'])) {
                        $Itm[$j]['sumVal'] = 0;
                        $Itm[$j]['sumCol'] = 0;
                    }
                    $Itm[$j]['sumVal'] += $val1 - $val2;
                    if ($ResITM[$j]["month_length_effect"] == 0 && $resPerInfo[0]['person_type'] == 3) {
                        $Itm[$j]['sumCol'] += round(($val1 - $val2) * $DayNo2 / 30);
                        $MainVal += round(($val1 - $val2) * $DayNo2 / 30);
                    } elseif ($resPerInfo[0]['person_type'] == 5 && $_SESSION['UserID'] == 'jafarkhani') {
                        // echo $endDate . "---<br>" ;
                        // echo DateModules::miladi_to_shamsi($res[$i]['current_execute_date'])."***<br>" ; die();
                        $arr3 = preg_split('/\\//', DateModules::miladi_to_shamsi($res[$i]['current_execute_date']));
                        $arr4 = preg_split('/\\//', DateModules::miladi_to_shamsi($endDate));
                        if ($arr4[1] * 1 == 1 && $arr4[0] == $arr3[0] + 1) {
                            $EP = 12;
                        } else {
                            $EP = $arr4[1] * 1;
                        }
                        //.........................
                        $std = $res[$i]['current_execute_date'];
                        $stMonth = $arr3[1] * 1;
                        if ($stMonth < 7) {
                            $endt = $arr3[0] . "/" . $arr3[1] . "/31";
                        } elseif (6 < $stMonth && $stMonth < 12) {
                            $endt = $arr3[0] . "/" . $arr3[1] . "/30";
                        } elseif ($stMonth == 12) {
                            $endt = $arr3[0] . "/" . $arr3[1] . "/29";
                        }
                        for ($k = $arr3[1] * 1; $k < $EP + 1; $k++) {
                            if (DateModules::CompareDate(DateModules::miladi_to_shamsi($endt), DateModules::miladi_to_shamsi($endDate)) < 1) {
                                $DYNo = round(DateModules::GDateMinusGDate(DateModules::shamsi_to_miladi($endt), $std)) + 1;
                                if ($stMonth < 7) {
                                    $mNO = 31;
                                } elseif ($stMonth > 6 && $stMonth < 12) {
                                    $mNO = 30;
                                } elseif ($stMonth == 12) {
                                    $mNO = 29;
                                }
                                $Itm[$j]['sumCol'] += round(($val1 - $val2) * $DYNo / $mNO);
                                $MainVal += round(($val1 - $val2) * $DYNo / $mNO);
                                $TaxInc += round(($val1 - $val2) * $DYNo / $mNO);
                                //........................
                                $std = DateModules::shamsi_to_miladi($arr3[0] . "/" . ($k + 1) . "/01");
                                $stMonth = $k + 1;
                                //$arr3[1] + 1;
                                if ($stMonth < 7) {
                                    $endt = $arr3[0] . "/" . $stMonth . "/31";
                                } elseif (6 < $stMonth && $stMonth < 12) {
                                    $endt = $arr3[0] . "/" . $stMonth . "/30";
                                } elseif ($stMonth == 12) {
                                    $endt = $arr3[0] . "/" . $stMonth . "/29";
                                }
                            } else {
                                //echo "****";
                                // die();
                                $endt = $endDate;
                                $DYNo = round(DateModules::GDateMinusGDate(DateModules::shamsi_to_miladi($endt), $std));
                                if ($stMonth < 7) {
                                    $mNO = 31;
                                } elseif ($stMonth > 6 && $stMonth < 12) {
                                    $mNO = 30;
                                } elseif ($stMonth == 12) {
                                    $mNO = 29;
                                }
                                $Itm[$j]['sumCol'] += round(($val1 - $val2) * $DYNo / $mNO);
                                $MainVal += round(($val1 - $val2) * $DYNo / $mNO);
                                $TaxInc += round(($val1 - $val2) * $DYNo / $mNO);
                                break;
                            }
                        }
                    } else {
                        $Itm[$j]['sumCol'] += round(($val1 - $val2) * $DayNo / 30);
                        $MainVal += round(($val1 - $val2) * $DayNo / 30);
                    }
                    //...............................
                    if ($RetRes[0]['retired_include'] == 1) {
                        $RetInc += $val1 - $val2;
                    }
                    if ($RetRes[0]['tax_include'] == 1 && $resPerInfo[0]['person_type'] != 5) {
                        if ($ResITM[$j]["month_length_effect"] == 0 && $resPerInfo[0]['person_type'] == 3) {
                            $TaxInc += round(($val1 - $val2) * $DayNo2 / 30);
                        } else {
                            $TaxInc += round(($val1 - $val2) * $DayNo / 30);
                        }
                    }
                    if ($RetRes[0]['insure_include'] == 1) {
                        $InsInc += $val1 - $val2;
                    }
                }
                //$MainVal = round(($sumDiff) * $DayNo / 30);
                //....................مالیات...........
                $qry = " select count(*) cn  \r\n\t\t\t\t\tfrom Arrear_payment_items \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . " and pay_month  = 12 and salary_item_type_id in (146,147,148,747)";
                $res4 = PdoDataAccess::runquery($qry);
                if ($res4[0]['cn'] > 0) {
                    //.........................................
                    $qry = " select count(*) cnp\r\n            from payments \r\n               where staff_id = " . $SID . " and pay_year = " . $t;
                    $resE = PdoDataAccess::runquery($qry);
                    if ($resE[0]['cnp'] == 0) {
                        $sdatetax = DateModules::shamsi_to_miladi($t . "/12/29");
                        $qry = " SELECT tti.from_value\r\n                FROM staff_tax_history sth\r\n                        inner join tax_tables tt on sth.tax_table_type_id = tt.tax_table_type_id\r\n                        inner join tax_table_items tti on tti.tax_table_id = tt.tax_table_id\r\n\r\n                WHERE sth.staff_id = " . $SID . " and \r\n                    sth.start_date < '" . DateModules::Now() . "' and\r\n                    ( sth.end_date = '0000-00-00' or sth.end_date is null or \r\n                    sth.end_date > '" . DateModules::Now() . "' ) and\r\n                    tt.from_date < '" . $sdatetax . "' and\r\n                    ( tt.to_date = '0000-00-00' or tt.to_date is null or tt.to_date >= '" . $sdatetax . "'  ) and coeficient = 0.1 ";
                        $resFval = PdoDataAccess::runquery($qry);
                        $TaxInc -= $resFval[0]['from_value'];
                    }
                    //.........................................
                    $RowTax = $TaxInc * 0.1;
                    //round(($TaxInc * $DayNo / 30) * 0.1);
                } else {
                    $RowTax = 0;
                }
                //..................................
                $qry = " select count(*) cn  \r\n\t\t\t\t\tfrom Arrear_payment_items \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . " and pay_month  = 12 and salary_item_type_id in (149 , 150)";
                $res3 = PdoDataAccess::runquery($qry);
                if ($res3[0]['cn'] > 0) {
                    $RowRet = round($RetInc * $DayNo / 30 * 0.09);
                } else {
                    $RowRet = 0;
                }
                //.......................بیمه تامین اجتماعی...........
                $qry = " select count(*) cn  \r\n\t\t\t\t\tfrom Arrear_payment_items \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . " and pay_month  = 12 and salary_item_type_id in (144,145,744,9920)";
                $res5 = PdoDataAccess::runquery($qry);
                if ($res5[0]['cn'] > 0) {
                    $RowInsure = round($InsInc * $DayNo / 30 * 0.07000000000000001);
                } else {
                    $RowInsure = 0;
                }
                //.....................................
                if ($resPerInfo[0]['last_retired_pay'] != NULL && $resPerInfo[0]['last_retired_pay'] != '0000-00-00' && DateModules::CompareDate($resPerInfo[0]['last_retired_pay'], DateModules::shamsi_to_miladi($t . "/01/01")) == -1) {
                    $RowRet = $retCoef = 0;
                }
                $TotalsumDiff += $sumDiff;
                $TotalMainVal += $MainVal;
                $TotalRowTax += $RowTax;
                $TotalRowRet += $RowRet;
                $TotalRowIns += $RowInsure;
                $TotalPay += $MainVal - ($RowTax + $RowRet + $RowInsure);
                /* $Row .= "<td>" . ( ($sumDiff < 0 ) ? CurrencyModulesclass::toCurrency($sumDiff) . "-" : CurrencyModulesclass::toCurrency($sumDiff)) . "</td>
                		 <td>" . (($MainVal < 0 ) ? CurrencyModulesclass::toCurrency($MainVal) . "-" : CurrencyModulesclass::toCurrency($MainVal)) . "</td><td>" .
                                  (($RowTax < 0 ) ? CurrencyModulesclass::toCurrency($RowTax) . "-" : CurrencyModulesclass::toCurrency($RowTax)) . "</td><td>" .
                                  (($RowRet < 0 ) ? CurrencyModulesclass::toCurrency($RowRet) . "-" : CurrencyModulesclass::toCurrency($RowRet)) . "</td><td>" .
                                  (($RowInsure < 0 ) ? CurrencyModulesclass::toCurrency($RowInsure) . "-" : CurrencyModulesclass::toCurrency($RowInsure)) . "</td><td>" .
                                  ((($MainVal - ($RowTax + $RowRet + $RowInsure )) < 0 ) ? CurrencyModulesclass::toCurrency(($MainVal - ($RowTax + $RowRet + $RowInsure))) . "-" : CurrencyModulesclass::toCurrency(($MainVal - ($RowTax + $RowRet + $RowInsure)))) . "</td></tr>"; */
            }
            //   $Row .= "</tr>";
        }
    }
Пример #5
0
function process_service_status_keys(&$data)
{
    static $serviceindex = 0;
    //get_standard_values($data, array('host_name', 'plugin_output', 'scheduled_downtime_depth', 'service_description', 'problem_has_been_acknowledged'));
    $data['serviceID'] = 'service' . $serviceindex++;
    //print "$serviceindex<br />";
    $service_states = array(0 => 'OK', 1 => 'WARNING', 2 => 'CRITICAL', 3 => 'UNKNOWN');
    if ($data['current_state'] == 0 && $data['last_check'] == 0) {
        $data['current_state'] = 'PENDING';
        $data['plugin_output'] = "No data received yet";
        $data['duration'] = "N/A";
        $data['attempt'] = "N/A";
        $data['last_check'] = "N/A";
    } else {
        $data['current_state'] = state_map($data['current_state'], $service_states);
        //UI display values
        $data['attempt'] = $data['current_attempt'] . ' / ' . $data['max_attempts'];
        $data['duration'] = calculate_duration($data['last_state_change']);
        $data['last_check'] = date('M d H:i\\:s\\s Y', intval($data['last_check']));
    }
}