예제 #1
0
function Thaiza($Header, $Birth_Date, $Image_1, $Image_2)
{
    $Now = date("j F Y");
    $Total_Day = datediff('d', $Now, $Birth_Date, false);
    if ($Total_Day <= 0) {
        $Week = 0;
        $Day = 0;
    } else {
        $Week = floor($Total_Day / 7);
        $Day = $Total_Day % 7;
    }
    $px_w = (40 - $Week) * 10;
    if ($px_w >= 360) {
        $px_w = 360;
    }
    if ($px_w <= 40) {
        $px_w = 40;
    }
    $String_2 = "{$Week} weeks and {$Day} days pregnant. Only {$Total_Day} days to go.";
    $image_1 = imagecreate(400, 100);
    $background_color = imagecolorallocate($image_1, 255, 255, 255);
    $image_2 = imagecreatefromjpeg($Image_1);
    $image_3 = imagecreatefromjpeg($Image_2);
    imagecopy($image_1, $image_2, 0, 20, 0, 0, 400, 60);
    imagecopymergegray($image_1, $image_3, $px_w, 20, 0, 0, 40, 60, 70);
    $Color = imagecolorallocate($image_1, 0, 0, 0);
    $px_1 = (imagesx($image_1) - 7.5 * strlen($Header)) / 2;
    $py_1 = imagesy($image_1) - 90;
    imagestring($image_1, 3, $px_1, $py_1, $Header, $Color);
    $px_2 = (imagesx($image_1) - 7.5 * strlen($String_2)) / 2;
    $py_2 = imagesy($image_1) - 20;
    imagestring($image_1, 3, $px_2, $py_2, $String_2, $Color);
    Header("Content-type: image/jpeg");
    imagepng($image_1);
    imagedestroy($image_1);
}
예제 #2
0
    }
} else {
    $auction_offer_move_link = "";
}
// End if
// UPDATE OFFER-VIEWS
$sql = "UPDATE " . AUCTION_OFFER_TABLE . "\r\n             SET auction_offer_views =  auction_offer_views + 1\r\n             WHERE PK_auction_offer_id = " . $auction_offer_id . "";
if (!($result = $db->sql_query($sql))) {
    message_die(GENERAL_ERROR, 'Could not update offer views', '', __LINE__, __FILE__, $sql);
}
$auction_offer_time_start = create_date($board_config['default_dateformat'], $auction_offer_row['auction_offer_time_start'], $board_config['board_timezone']);
$auction_offer_time_stop = create_date($board_config['default_dateformat'], $auction_offer_row['auction_offer_time_stop'], $board_config['board_timezone']);
if ($auction_offer_row['auction_offer_time_stop'] < time()) {
    $auction_time_remaining = '-';
} else {
    $auction_time_remaining = datediff(time(), $auction_offer_row['auction_offer_time_stop']);
}
// create auction-offer-message (not started, active, or over)
if ($auction_offer_row['auction_offer_time_start'] > time()) {
    $auction_offer_time_message = "<font color=\"red\">" . $lang['auction_offer_not_started'] . "</font>";
} elseif ($auction_offer_row['auction_offer_time_stop'] < time()) {
    $auction_offer_time_message = "<font color=\"red\">" . $lang['auction_offer_over'] . "</font>";
} else {
    $auction_offer_time_message = "<font color=\"red\">" . $lang['auction_offer_status_active'] . "</font>";
}
// getting seller-info
$sql = "SELECT u.username,\r\n                    u.user_id,\r\n                    u.user_posts,\r\n                    u.user_from,\r\n                    u.user_website,\r\n                    u.user_email,\r\n                    u.user_icq,\r\n                    u.user_aim,\r\n                    u.user_yim,\r\n                    u.user_regdate,\r\n                    u.user_msnm,\r\n                    u.user_viewemail,\r\n                    u.user_rank,\r\n                    u.user_sig,\r\n                    u.user_sig_bbcode_uid,\r\n                    u.user_avatar,\r\n                    u.user_avatar_type,\r\n                    u.user_allowavatar,\r\n                    u.user_allowsmile\r\n            FROM " . USERS_TABLE . " u\r\n            WHERE  u.user_id = " . $auction_offer_row['user_id'] . "";
if (!($result = $db->sql_query($sql))) {
    message_die(GENERAL_ERROR, "Could not obtain post/user information.", '', __LINE__, __FILE__, $sql);
}
$sellerrow = array();
	function get_kunjungan($val) {
		unset($_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk]);
		$tgl_start = @date("Y-m-d", @mktime(1,1,1,$val[tgl_periksa_bln_start], $val[tgl_periksa_tgl_start], $val[tgl_periksa_thn_start]));
		$tgl_end = @date("Y-m-d", @mktime(1,1,1,$val[tgl_periksa_bln_end], $val[tgl_periksa_tgl_end], $val[tgl_periksa_thn_end]));
		$title = "Statistik Kunjungan Radiologi Berdasar Cara Masuk";
		
		if($val[tampilkan] == "hari") {
			$selisih = datediff('d', $tgl_start, $tgl_end);
			$tanggal_awal = tanggalIndo($tgl_start, "j F Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "j F Y");
		} elseif($val[tampilkan] == "bulan") {
			$selisih = datediff('m', $tgl_start, $tgl_end);
			$tanggal_awal = tanggalIndo($tgl_start, "F Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "F Y");
		} else {
			$selisih = datediff('y', $tgl_start, $tgl_end);
			$tanggal_awal = tanggalIndo($tgl_start, "Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "Y");
		}

		$title .= "\nPeriode " . $tanggal_awal . " s.d. " . $tanggal_akhir;

		$arr_tgl_start = explode("-",$tgl_start);
		$tgl_start_tgl = $arr_tgl_start[2];
		$tgl_start_bln = $arr_tgl_start[1];
		$tgl_start_thn = $arr_tgl_start[0];

		$arr_tgl_end = explode("-",$tgl_end);
		$tgl_end_tgl = $arr_tgl_end[2];
		$tgl_end_bln = $arr_tgl_end[1];
		$tgl_end_thn = $arr_tgl_end[0];

		$objResponse = new xajaxResponse();
		$kon = new Konek;

		for($i=0;$i<=$selisih;$i++) {
			if($val[tampilkan] == "hari") {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, $tgl_start_bln, ($i+$tgl_start_tgl), $tgl_start_thn));
				$tgl_periksa[$i] = tanggalIndo($tgl[$i], "j M\nY");
				$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][radioel_tick][$i] = @date("j", @mktime(1, 1, 1,$tgl_start_bln, ($tgl_start_tgl+$i), $tgl_start_thn));
				$radioel_x[$i] = @date("M Y", @mktime(1, 1, 1, $tgl_start_bln, ($tgl_start_tgl+$i), $tgl_start_thn));
				$where = " AND DATE(lk.tgl_periksa) = '" . $tgl[$i] . "' ";
			} elseif($val[tampilkan] == "bulan") {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$tgl_periksa[$i] = tanggalIndo($tgl[$i], "M\nY");
				$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][radioel_tick][$i] = @date("M y", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$radioel_x[$i] = @date("Y", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$where = " AND EXTRACT(YEAR_MONTH FROM lk.tgl_periksa) = EXTRACT(YEAR_MONTH FROM '" . $tgl[$i] . "') ";
			} else {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, 1, 1, ($tgl_start_thn + $i)));
				$tgl_periksa[$i] = tanggalIndo($tgl[$i], "Y");
				$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][radioel_tick][$i] = @date("Y", @mktime(1, 1, 1, 1, 1, ($tgl_start_thn+$i)));
				$radioel_x[$i] = "Tahun";
				$where = " AND YEAR(lk.tgl_periksa) = YEAR('" . $tgl[$i] . "') ";
			}
			//dari IRD
			$kon->sql = "
				SELECT
					COUNT(lk.id) as jml_igd
				FROM
					radio_kunjungan lk 
					JOIN pasien p ON (p.id = lk.pasien_id)
				WHERE
					lk.cara_masuk = 'IGD'
					$where
			";
			$kon->execute();
			$igd[$i] = $kon->getOne();
			if(!$igd[$i][jml_igd]) $igd[$i][jml_igd] = "-";


			//dari RAWAT JALAN
			$kon->sql = "
				SELECT
					COUNT(lk.id) as jml_rajal
				FROM
					radio_kunjungan lk 
					JOIN pasien p ON (p.id = lk.pasien_id)
				WHERE
					lk.cara_masuk = 'RAWAT JALAN'
					$where
			";
			$kon->execute();
			$rajal[$i] = $kon->getOne();
			if(!$rajal[$i][jml_rajal]) $rajal[$i][jml_rajal] = "-";


			//dari RAWAT INAP
			$kon->sql = "
				SELECT
					COUNT(lk.id) as jml_ranap
				FROM
					radio_kunjungan lk 
					JOIN pasien p ON (p.id = lk.pasien_id)
				WHERE
					lk.cara_masuk = 'RAWAT INAP'
					$where
			";
			$kon->execute();
			$ranap[$i] = $kon->getOne();
			if(!$ranap[$i][jml_ranap]) $ranap[$i][jml_ranap] = "-";


			//dari RAWAT INAP
			$kon->sql = "
				SELECT
					COUNT(lk.id) as jml_luar
				FROM
					radio_kunjungan lk 
					JOIN pasien p ON (p.id = lk.pasien_id)
				WHERE
					lk.cara_masuk = 'PASIEN LUAR'
					$where
			";
			$kon->execute();
			$luar[$i] = $kon->getOne();
			if(!$luar[$i][jml_luar]) $luar[$i][jml_luar] = "-";

			$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][jml_igd][$i] = $igd[$i][jml_igd];
			$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][jml_rajal][$i] = $rajal[$i][jml_rajal];
			$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][jml_ranap][$i] = $ranap[$i][jml_ranap];
			$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][jml_luar][$i] = $luar[$i][jml_luar];

			$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][tgl_periksa][$i] = $tgl_periksa[$i];
		}
		//$objResponse->addAlert(print_r($lama));
		$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][title] = $title . "\nPeriode " . tanggalIndo($tgl_start, "j F Y") . " s.d. " . tanggalIndo($tgl_end, "j F Y");
		$radioelx = @array_unique($radioel_x);
		$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][radioel_x] = @implode(", ",$radioelx);

		$table = new Table;
		$table->scroll = false;
		//$table->Th[0][] = "Pelayanan";
		//$table->extra_th[0][] = "rowspan=\"2\"";
		for($i=0;$i<=$selisih;$i++) {
			$table->Th[0][] = $tgl_periksa[$i];
			$table->extra_th[0][] = "colspan=\"4\"";
		}
		$table->Th[0][] = "Jumlah";
		$table->extra_th[0][] = "colspan=\"4\"";
		$kolom = $selisih*4+3;
		for($i=0;$i<=$selisih;$i++) {
			$table->Th[1][] = "IRD";
			$table->Th[1][] = "Rajal";
			$table->Th[1][] = "Ranap";
			$table->Th[1][] = "Px Luar";
			$table->Th[2][] = $i*4+1;
			$table->Th[2][] = $i*4+2;
			$table->Th[2][] = $i*4+3;
			$table->Th[2][] = $i*4+4;
		}
		$table->Th[2][] = $i*4+1;
		$table->Th[2][] = $i*4+2;
		$table->Th[2][] = $i*4+3;
		$table->Th[2][] = $i*4+4;
		//kolom jumlah
		$table->Th[1][] = "IRD";
		$table->Th[1][] = "Rajal";
		$table->Th[1][] = "Ranap";
		$table->Th[1][] = "Px Luar";

		//isinya
		//$table->Row[0][0] = "IGD";
		for($i=0;$i<=$selisih;$i++) {
			$table->Row[0][] = $igd[$i][jml_igd];
			$table->Row[0][] = $rajal[$i][jml_rajal];
			$table->Row[0][] = $ranap[$i][jml_ranap];
			$table->Row[0][] = $luar[$i][jml_luar];
			$jumlah[igd] += $igd[$i][jml_igd];
			$jumlah[rajal] += $rajal[$i][jml_rajal];
			$jumlah[ranap] += $ranap[$i][jml_ranap];
			$jumlah[luar] += $luar[$i][jml_luar];
		}

		//kolom terakhir
		$table->Row[0][] = $jumlah[igd];
		$table->Row[0][] = $jumlah[rajal];
		$table->Row[0][] = $jumlah[ranap];
		$table->Row[0][] = $jumlah[luar];
		$ret = $table->build();

		$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][th_0] = $table->Th[0];
		$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][th_1] = $table->Th[1];
		$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][extra_th_0] = $table->extra_th[0];
		$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][row] = $table->Row[0];
		
		$objResponse->addAssign("list_data", "innerHTML", $ret);
		$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][graph] = "<img src=\"" . URL . "rekmed/statistik_kunjungan_radio_semua_cara_masuk_graph_line/?md5=".md5(date("Ymdhis"))."\" alt=\"Kunjungan\" />";
		$_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][title] = $title;
		$objResponse->addAssign("title", "innerHTML", nl2br($_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][title]));
		$objResponse->addAssign("graph", "innerHTML", $_SESSION[rekmed][statistik_kunjungan_radio_semua_cara_masuk][graph]);
		return $objResponse;
	}
예제 #4
0
function generate_cashflow_array($category_array_organised, $date_today)
{
    // generates an array containing the data for main cashflow table
    // used later for outputting a table of the data
    //
    // $payments_all 	= array of the details of all payments - from the DB
    // #numdata_cols 	= number of days to forecast (minus 1 as it starts at 0)
    // $date_today		= today's date
    // $cat_array = categories
    // $pay_array = payments
    global $payment_types;
    // small array of different types of payments
    global $payment_types_qualifier;
    // small array of text for different types of payments
    global $payment_types_historic;
    global $payment_date_suffixes;
    // small array of date suffixes e.g. "rd" to help create "3rd"
    global $daysofweek;
    // small array of days of week words
    global $daysoffortnight;
    // small array of days of fortnight words
    global $numdata_cols;
    global $database;
    // medoo database connection
    global $green, $amber, $red;
    global $date_today, $date_today_long, $date_today_sql;
    foreach ($category_array_organised as $data) {
        if ($data["catorpay"] == "Category") {
            // create a row for each category
            $this_category = $data["id"];
            unset($cashflow_row);
            $cashflow_row["attr"] = "data-tt-id='" . $data['id'] . "' data-tt-grandparents-array='" . $data['grandparents'] . "' data-tt-parent-id='" . $data['parent'] . "'";
            // <TR> attributes for this payment for later reference
            $add_new_payment = "";
            //Name column
            if ($data["id"] == 1) {
                $add_new_payment = "\n\t\t\t\t<a id='newpayment_showhide' class='box1a btnsmall'>Add new payment</a><a id='newcategory_showhide' class='box1a btnsmall'>Add new category</a></small>\n\t\t\t\t<div class='box1'>\n\t\t\t\t\t<div class='box3' id='newpayment_showhide_panel'>\n\t\t\t\t\t" . generate_add_new_payment_form() . "\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class='box4' id='newcategory_showhide_panel'>\n\t\t\t\t\t" . generate_add_new_category_form() . "\n\t\t\t\t\t</div>\n\t\t\t\t</div>";
            }
            $cashflow_row["name"] = "<nobr><span class='folder'>" . $data["name"] . "</span>" . " <small><a href='#' class='btnsmall xedit_noreload' data-name='category_name' data-pk='" . $data["id"] . "' data-url='/forecast/post.php'" . "data-title='Enter Category Name' data-type='text' data-value='" . $data["name"] . "'>edit</a></small></nobr>" . $add_new_payment;
            // text field / original value
            //Historic (Total)
            if ($data["id"] == 1) {
                // if its the first row, display all uncategorised transactions, ie those with no transaction_category assigned
                $history_select_criteria = array("transaction_category" => null);
                $cashflow_row["historic"] = generate_cashflow_array_historic($history_select_criteria, $data);
                //column of payment history
                //echo $date_today_sql;
            } else {
                $cashflow_row["historic"] = array("", "class='history_show'");
            }
            //Historic (Average)
            $cashflow_row["historic_average"] = array("", "class='history_show'");
            //Historic (Previous)
            $cashflow_row["historic_previous"] = array("", "class='history_show'");
            $cashflow_row["frequency"] = "";
            //column of payment frequencies - blank for category
            $cashflow_row["date"] = "";
            //column of payment dates - blank for category
            $cashflow_row["value"] = "";
            // column of payment values - blank for category
            for ($date = 0; $date <= $numdata_cols; $date++) {
                // actual data columns of values - blank for category
                $cashflow_row[] = "";
            }
            $cashflow_array[] = $cashflow_row;
            // assign completed row array to the return array
            // row to test reordering
            //$cashflow_row_test = array("attr" => "data-tt-id='10".$data['id']."' data-tt-grandparents-array='0' data-tt-parent-id='0' class='reorder'","name" => "<nobr><span class='reorder'></span>","historic" => "","historic_average" => "","historic_previous" => "","frequency" => "","date" => "","value" => "");
            //For ($date=0; $date<=$numdata_cols; $date++) {
            //	$cashflow_row_test[]="";
            //}
            //$cashflow_array[] = $cashflow_row_test;
        } else {
            // create a row for each payment
            //echo"payment";
            unset($cashflow_row);
            $paymentisactive = $data['active'];
            $cashflow_row["attr"] = "class='" . ($paymentisactive ? "" : "inactive") . "' data-pay-id='" . $data['id'] . "' data-tt-id='item-" . $data['id'] . "' data-tt-parent-id='" . $data['parent'] . "'";
            //$data["attr"]; // <TR> attributes for this payment for later reference
            //payment name, array of td contents & td attributes
            $cashflow_row["name"] = array("<nobr><span class='file" . ($paymentisactive ? "" : "inactive") . "'>" . $data["name"] . "</span> <small>" . "<a href='#' class='btnsmall xedit_noreload' data-name='payment_name' data-pk='" . $data["id"] . "' data-url='/forecast/post.php'" . "data-title='Enter Payment Name' data-type='text' data-value='" . $data["name"] . "'>edit</a></small> " . ($paymentisactive ? "<small><a href='#' class='btnsmall payment_active' data-name='payment_active' data-pk='" . $data["id"] . "' data-url='/forecast/post.php' data-value='0'>deactivate</a></small></nobr>" : "<small><a href='#' class='btnsmall payment_active' data-name='payment_active' data-pk='" . $data["id"] . "' data-url='/forecast/post.php' data-value='1'>make active</a><a class='btnsmall deletepayment_showhide'>Delete!</a></small></nobr>\n\t\t\t<div class='box1'>\n\t\t\t\t<div class='box3 deletepayment_showhide_panel'>\n\t\t\t\tAre you Sure you want to delete this payment?<br><br>\n\t\t\t\tSelect another payment to associate it's transations category rules to, or select none to recategorise them at a later time.\n\t\t\t\t[TBC - insert dropdown of payments with additional NONE option]\n\t\t\t\t</div>\n\t\t\t</div>"), "class='payment_cell'");
            //attributes for this td
            //Historic Total
            $history_select_criteria = array("transaction_category" => $data["id"]);
            $cashflow_row["historic"] = generate_cashflow_array_historic($history_select_criteria, $data);
            //Historic Average
            $history_select_criteria = array("transaction_category" => $data["id"]);
            $cashflow_row["historic_average"] = generate_cashflow_array_historic($history_select_criteria, $data, "average", " per " . $payment_types_historic[$data["type"]]);
            //Historic Previous
            //determine the start date for the previous period based on frequency type
            switch ($data["type"]) {
                case 1:
                    // Weekly =			Day of Week: 0 = Sun, 1 = Mon etc
                    $date_offset = 7;
                    break;
                case 2:
                    // 2. Fortnightly = Start date: 21 Feb 2016
                    $date_offset = 14;
                    break;
                case 3:
                    // Monthly = 	Day of Month: 21 (up to 28 to avoid Feb issues)
                    $date_offset = 30;
                    break;
                case 4:
                    // 4. Quarterly =	Start Date: 21 Feb 2016
                    $date_offset = 120;
                    break;
                case 5:
                    // 5. Annual = 		Start Date: 21 Feb 2016
                    $date_offset = 365;
                    break;
                    //echo $date_offset;
                //echo $date_offset;
                default:
                    // 0. Once-off = 	Start date: 21 Feb 2016
                    $date_offset = 365;
            }
            $startdate = date("Y-m-d H:i:s", strtotime($date_today) - $date_offset * 24 * 60 * 60);
            //echo $date_offset;
            $history_select_criteria = array("AND" => array("transaction_category" => $data["id"], "transaction_date[>]" => $startdate));
            //$history_select_criteria = '["AND" => ["transaction_category" => '.$data["id"].',"transaction_date[>]" => "'.$startdate.'"]]';
            //["AND" => ["transaction_category" => $data["id"],"transaction_date[>]" => "2016-03-03 00:00:00"]]
            $cashflow_row["historic_previous"] = generate_cashflow_array_historic($history_select_criteria, $data, "previous", " last " . $payment_types_historic[$data["type"]]);
            //column of payment frequencies
            $cashflow_row["frequency"] = array("<nobr>" . $payment_types[$data["type"]] . " <small>" . $payment_types_qualifier[$data["type"]] . " <a href='#' class='btnsmall xedit_select_frequency' data-value='" . $data["type"] . "' data-name='payment_type' data-type='select' data-pk='" . $data["id"] . "' data-url='/forecast/post.php' data-title='Select Payment Type'>edit</a></small></nobr>", "class='payment_cell'");
            //column of payment dates
            switch ($data["type"]) {
                case 1:
                    // Weekly =			Day of Week: 0 = Sun, 1 = Mon etc
                    $cashflow_row["date"] = array("<nobr>" . $daysofweek[$data["dayofweek"]] . " <small><a href='#' class='btnsmall xedit_select_dayofweek' id='payment_dayofweek_" . $data["id"] . "' data-name='payment_dayofweek' data-type='select' data-pk='" . $data["id"] . "' data-url='/forecast/post.php' data-title='Select Day' data-value='" . $data["dayofweek"] . "' data-original-title title>edit</a></small></nobr>", "class='payment_cell'");
                    break;
                case 2:
                    // 2. Fortnightly = Start date: 21 Feb 2016
                    $cashflow_row["date"] = array("<nobr>" . $daysoffortnight[$data["dayoffortnight"]] . " <small><a href='#' class='btnsmall xedit_select_dayoffortnight' id='payment_dayoffortnight_" . $data["id"] . "' data-name='payment_dayoffortnight' data-type='select' data-pk='" . $data["id"] . "' data-url='/forecast/post.php' data-title='Select Day' data-value='" . $data["dayoffortnight"] . "' data-original-title title>edit</a></small></nobr>", "class='payment_cell'");
                    break;
                case 3:
                    // Monthly = 	Day of Month: 21 (up to 28 to avoid Feb issues)
                    $cashflow_row["date"] = array("<nobr>" . $data["dayofmonth"] . "<small>" . $payment_date_suffixes[$data["dayofmonth"]] . "</small>" . " <small><a href='#' class='btnsmall xedit_select_dayofmonth' id='payment_dayofmonth_" . $data["id"] . "' data-name='payment_dayofmonth' data-type='select' data-pk='" . $data["id"] . "' data-url='/forecast/post.php' data-title='Select Date' data-value='" . $data["dayofmonth"] . "' data-original-title title>edit</a></small></nobr>", "class='payment_cell'");
                    break;
                case 4:
                    // 4. Quarterly =	Start Date: 21 Feb 2016
                    $quart_date = date("d M Y", strtotime($data["startdate"])) . "</nobr>";
                    $cashflow_row["date"] = array("<nobr>" . $quart_date . " <small><a href='#' class='btnsmall xedit_datepicker_startdate editable-open' id='payment_startdate_" . $data["id"] . "' data-name='payment_startdate' data-type='date' data-format='yyyy-mm-d' data-viewformat='yyyy-mm-d' data-template='yyyy-mm-d' data-pk='" . $data["id"] . "' data-url='/forecast/post.php' data-title='Select Start Date' data-value='" . $data["startdate"] . "' data-original-title title>edit</a></small></nobr>", "class='payment_cell'");
                    break;
                case 5:
                    // 5. Annual = 		Start Date: 21 Feb 2016
                    $cashflow_row["date"] = array("<nobr>" . date("d M", strtotime($data["startdate"])) . " <small><a href='#' class='btnsmall xedit_datepicker_startdate editable-open' id='payment_startdate_" . $data["id"] . "' data-name='payment_startdate' data-type='date' data-format='yyyy-mm-d' data-viewformat='yyyy-mm-d' data-template='yyyy-mm-d' data-pk='" . $data["id"] . "' data-url='/forecast/post.php' data-title='Select Start Date' data-value='" . $data["startdate"] . "' data-original-title title>edit</a></small></nobr>", "class='payment_cell'");
                    break;
                default:
                    // 0. Once-off = 	Start date: 21 Feb 2016
                    $cashflow_row["date"] = array("<nobr>" . date("d M Y", strtotime($data["startdate"])) . " <small><a href='#' class='btnsmall xedit_datepicker_startdate editable-open' id='payment_startdate_" . $data["id"] . "' data-name='payment_startdate' data-type='date' data-format='yyyy-mm-d' data-viewformat='yyyy-mm-d' data-template='yyyy-mm-d' data-pk='" . $data["id"] . "' data-url='/forecast/post.php' data-title='Select Start Date' data-value='" . $data["startdate"] . "' data-original-title title>edit</a></small></nobr>", "class='payment_cell'");
            }
            // column of payment values
            $temp_value = "<nobr>" . format_dolla($data["value"]) . "</nobr> <small><a href='#' class='btnsmall xedit' id='payment_value_edit_" . $data["id"] . "' data-name='payment_value' data-type='text' data-pk='" . $data["id"] . "' data-url='/forecast/post.php' data-title='Enter Payment Value' data-value='" . $data["value"] . "'>edit</a></small>";
            if ($data["value"] <= 0) {
                $cashflow_row["value"] = array($temp_value, "class='payment_cell'");
            } else {
                $cashflow_row["value"] = array($temp_value, "bgcolor='" . $green . "' class='payment_cell'");
            }
            if (!$paymentisactive) {
                //if payment is not active, don't include values in main table
                for ($date = 0; $date <= $numdata_cols; $date++) {
                    $cashflow_row[] = array(0, "class='payment_cell'");
                }
                $cashflow_array[] = $cashflow_row;
            } else {
                switch ($data["type"]) {
                    //column of payment types
                    case 1:
                        // Weekly =			Day of Week: 0 = Sun, 1 = Mon etc
                        for ($date = 0; $date <= $numdata_cols; $date++) {
                            //calculate if this payment applies to each date column
                            $col_date = date("w", strtotime("+" . $date . " day", strtotime($date_today)));
                            if ($col_date == $data["dayofweek"]) {
                                $cashflow_row[] = array($data["value"], "class='payment_cell'");
                            } else {
                                $cashflow_row[] = array(0, "class='payment_cell'");
                            }
                        }
                        break;
                    case 2:
                        // 2. Fortnightly = Start date: 21 Feb 2016
                        for ($date = 0; $date <= $numdata_cols; $date++) {
                            //calculate if this payment applies to each date column
                            $col_day = $daysoffortnight[date("w", strtotime("+" . $date . " day", strtotime($date_today)))];
                            $col_date = date("j F Y", strtotime("+" . $date . " day", strtotime($date_today)));
                            if (datediff('ww', '3 January 2016', $col_date, false) & 1) {
                                $iswk2 = "";
                            } else {
                                $iswk2 = "-wk2";
                            }
                            if ($col_day . $iswk2 == $daysoffortnight[$data["dayoffortnight"]]) {
                                $cashflow_row[] = array($data["value"], "class='payment_cell'");
                            } else {
                                $cashflow_row[] = array(0, "class='payment_cell'");
                            }
                        }
                        break;
                    case 3:
                        // Monthly = 	Day of Month: 21 (up to 28 to avoid Feb issues)
                        for ($date = 0; $date <= $numdata_cols; $date++) {
                            //calculate if this payment applies to each date column
                            $col_date = date("j", strtotime("+" . $date . " day", strtotime($date_today)));
                            if ($col_date == $data["dayofmonth"]) {
                                $cashflow_row[] = array($data["value"], "class='payment_cell'");
                            } else {
                                $cashflow_row[] = array(0, "class='payment_cell'");
                            }
                        }
                        break;
                    case 4:
                        // 4. Quarterly =	Start Date: 21 Feb 2016
                        $quart_date = date("d M Y", strtotime($data["startdate"]));
                        for ($date = 0; $date <= $numdata_cols; $date++) {
                            //calculate if this payment applies to each date column
                            $col_date = date("d M Y", strtotime("+" . $date . " day", strtotime($date_today)));
                            $col_date2 = date("d M Y", strtotime("+90 day", strtotime($date_today)));
                            $col_date3 = date("d M Y", strtotime("+180 day", strtotime($date_today)));
                            $col_date4 = date("d M Y", strtotime("+270 day", strtotime($date_today)));
                            if ($quart_date == $col_date || $quart_date == $col_date2 || $quart_date == $col_date3 || $quart_date == $col_date4) {
                                $cashflow_row[] = array($data["value"], "class='payment_cell'");
                            } else {
                                $cashflow_row[] = array(0, "class='payment_cell'");
                            }
                        }
                        break;
                    case 5:
                        // 5. Annual = 		Start Date: 21 Feb 2016
                        for ($date = 0; $date <= $numdata_cols; $date++) {
                            //calculate if this payment applies to each date column
                            $col_date = date("d M", strtotime("+" . $date . " day", strtotime($date_today)));
                            if ($col_date == date("d M", strtotime($data["startdate"]))) {
                                $cashflow_row[] = array($data["value"], "class='payment_cell'");
                            } else {
                                $cashflow_row[] = array(0, "class='payment_cell'");
                            }
                        }
                        break;
                    default:
                        // 0. Once-off = 	Start date: 21 Feb 2016
                        for ($date = 0; $date <= $numdata_cols; $date++) {
                            //calculate if this payment applies to each date column
                            $col_date = date("d m Y", strtotime("+" . $date . " day", strtotime($date_today)));
                            if ($col_date == date("d m Y", strtotime($data["startdate"]))) {
                                $cashflow_row[] = array($data["value"], "class='payment_cell'");
                            } else {
                                $cashflow_row[] = array(0, "class='payment_cell'");
                            }
                        }
                }
                $cashflow_array[] = $cashflow_row;
            }
        }
    }
    //print_r_pre($cashflow_row);
    return $cashflow_array;
}
예제 #5
0
function includeAuctionSpecialBlock()
{
    global $template, $lang, $db, $board_config, $userdata, $phpEx, $images;
    $auction_config_data = init_auction_config();
    // Just display if switched on via ACP
    if ($auction_config_data['auction_block_display_specials'] == 1) {
        $sql = "SELECT PK_auction_offer_id,\r\n                                    auction_offer_title,\r\n                                    auction_offer_picture,\r\n                                    auction_offer_time_stop\r\n                             FROM " . AUCTION_OFFER_TABLE . "\r\n                             WHERE auction_offer_state=0 AND\r\n                                   auction_offer_special=1 AND\r\n                                   auction_offer_paid=1 AND\r\n                                   auction_offer_time_start < " . time() . " AND\r\n                                   auction_offer_time_stop > " . time() . "\r\n                             ORDER BY auction_offer_time_stop DESC\r\n                             LIMIT 0, " . $auction_config_data['auction_block_specials_limit'] . "";
        if (!($result = $db->sql_query($sql))) {
            message_die(GENERAL_ERROR, 'Could not query news', '', __LINE__, __FILE__, $sql);
        }
        // End if
        $specials_count = 0;
        $specials_row = array();
        while ($row = $db->sql_fetchrow($result)) {
            $specials_row[] = $row;
            $specials_count++;
        }
        // End while
        $template->assign_block_vars('special_block', array('L_AUCTION_SPECIAL_OFFERS_TITLE' => $lang['auction_special_offers']));
        for ($i = 0; $i < $specials_count; $i++) {
            $auction_offer_id = $specials_row[$i]['PK_auction_offer_id'];
            // BEGIN include auction-pic-config information
            $auction_config_pic = init_auction_config_pic();
            // END include auction-pic-config information
            // get info for admin and mod. Admin and mod see the offer-pic even if it has not been validated yet
            // this is only valid if validation is active
            if ($auction_config_pic['auction_offer_pic_approval_admin'] == 1) {
                if ($userdata['user_level'] == ADMIN or $userdata['user_level'] == MOD) {
                    $x_sql = "";
                } else {
                    $x_sql = "AND pic_approval = 0 AND pic_lock = 0 ";
                }
            } else {
                if ($userdata['user_level'] == ADMIN or $userdata['user_level'] == MOD) {
                    $x_sql = "";
                } else {
                    $x_sql = "AND pic_lock = 0 ";
                }
            }
            // specials pictures
            $sql = "SELECT pic_id, crop_id\r\n\t\t\t\tFROM " . AUCTION_IMAGE_TABLE . "\r\n\t\t\t\tWHERE pic_auction_id = '{$auction_offer_id}' AND\r\n                                      pic_main = 1 {$x_sql}";
            if (!($result = $db->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Could not get pic  special-offer information  for auction id: ' . $auction_offer_id, '', __LINE__, __FILE__, $sql);
            }
            $pic_row = $db->sql_fetchrow($result);
            $mini_pic_id = $pic_row['pic_id'];
            $mini_crop_id = $pic_row['crop_id'];
            if ($mini_pic_id > 0) {
                $pic_yes = 1;
                $image_url = append_sid('auction_thumbnail.' . $phpEx . '?pic_type=3&crop=' . $mini_crop_id . '&pic_id=' . $mini_pic_id);
                $pic_width = $auction_config_pic['auction_offer_mini_size'];
                $pic_height = $auction_config_pic['auction_offer_mini_size'];
            } else {
                $pic_yes = 0;
            }
            // special pictures end
            $template->assign_block_vars('special_block.special_offer_block', array('AUCTION_SPECIAL_TITLE' => subStr($specials_row[$i]['auction_offer_title'], 0, 20), 'U_AUCTION_SPECIAL_TITLE' => append_sid("auction_offer_view.php?" . POST_AUCTION_OFFER_URL . "=" . $specials_row[$i]['PK_auction_offer_id']), 'AUCTION_SPECIAL_END' => datediff(time(), $specials_row[$i]['auction_offer_time_stop']), 'AUCTION_SPECIAL_IMAGE' => $pic_yes == 0 ? '<a href="' . append_sid("auction_offer_view.php?" . POST_AUCTION_OFFER_URL . "=" . $specials_row[$i]['PK_auction_offer_id']) . '"><img src="' . $images['icon_auction_no_pic'] . '" alt="' . $lang['auction_user_rating_view_offer'] . '" title="' . $lang['auction_user_rating_view_offer'] . '" border="0" /></a>' : '<a href="' . append_sid("auction_offer_view.php?" . POST_AUCTION_OFFER_URL . "=" . $specials_row[$i]['PK_auction_offer_id']) . '"><img src="' . $image_url . '" width="' . $pic_width . '" height="' . $pic_height . '" alt="' . $lang['auction_user_rating_view_offer'] . '" title="' . $lang['auction_user_rating_view_offer'] . '" border="0" /></a>'));
        }
        // End for
    }
    // End if
}
	function get_kunjungan($val) {
		unset($_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar]);
		$tgl_start = @date("Y-m-d", @mktime(1,1,1,$val[tgl_periksa_bln_start], $val[tgl_periksa_tgl_start], $val[tgl_periksa_thn_start]));
		$tgl_end = @date("Y-m-d", @mktime(1,1,1,$val[tgl_periksa_bln_end], $val[tgl_periksa_tgl_end], $val[tgl_periksa_thn_end]));
		$title = "Rekapitulasi Jumlah Cara Pembayaran di Unit Rawat Jalan";
		
		if($val[tampilkan] == "hari") {
			$selisih = datediff('d', $tgl_start, $tgl_end);
		} elseif($val[tampilkan] == "bulan") {
			$selisih = datediff('m', $tgl_start, $tgl_end);
		} else {
			$selisih = datediff('y', $tgl_start, $tgl_end);
		}
		if($val[tampilkan] == "hari") {
			$tanggal_awal = tanggalIndo($tgl_start, "j F Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "j F Y");
		} elseif($val[tampilkan] == "bulan") {
			$tanggal_awal = tanggalIndo($tgl_start, "F Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "F Y");
		} else {
			$tanggal_awal = tanggalIndo($tgl_start, "Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "Y");
		}

		$title .= "\nPeriode " . $tanggal_awal . " s.d. " . $tanggal_akhir;

		$arr_tgl_start = explode("-",$tgl_start);
		$tgl_start_tgl = $arr_tgl_start[2];
		$tgl_start_bln = $arr_tgl_start[1];
		$tgl_start_thn = $arr_tgl_start[0];

		$arr_tgl_end = explode("-",$tgl_end);
		$tgl_end_tgl = $arr_tgl_end[2];
		$tgl_end_bln = $arr_tgl_end[1];
		$tgl_end_thn = $arr_tgl_end[0];

		$objResponse = new xajaxResponse();
		$kon = new Konek;
	
		for($i=0;$i<=$selisih;$i++) {
			if($val[tampilkan] == "hari") {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, $tgl_start_bln, ($i+$tgl_start_tgl), $tgl_start_thn));
				$data[$i][tgl_periksa] = tanggalIndo($tgl[$i], "j M Y");
				$_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar][label_tick][$i] = @date("j", @mktime(1, 1, 1,$tgl_start_bln, ($tgl_start_tgl+$i), $tgl_start_thn));
				$label_x[$i] = @date("M Y", @mktime(1, 1, 1, $tgl_start_bln, ($tgl_start_tgl+$i), $tgl_start_thn));
				$where = " AND DATE(kk.tgl_periksa) = '" . $tgl[$i] . "'";
			} elseif($val[tampilkan] == "bulan") {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$data[$i][tgl_periksa] = tanggalIndo($tgl[$i], "M Y");
				$_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar][label_tick][$i] = @date("M y", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$label_x[$i] = @date("Y", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$where = " AND EXTRACT(YEAR_MONTH FROM kk.tgl_periksa) = EXTRACT(YEAR_MONTH FROM '" . $tgl[$i] . "')";
			} else {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, 1, 1, ($tgl_start_thn + $i)));
				$data[$i][tgl_periksa] = tanggalIndo($tgl[$i], "Y");
				$_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar][label_tick][$i] = @date("Y", @mktime(1, 1, 1, 1, 1, ($tgl_start_thn+$i)));
				$label_x[$i] = "Tahun";
				$where = " AND YEAR(kk.tgl_periksa) = YEAR('" . $tgl[$i] . "')";
			}
			$sql = "
				SELECT
					kk.cara_bayar as nama, 
					COUNT(kk.id) as jml
				FROM
					kunjungan_kamar kk 
					JOIN kamar kmr ON (kmr.id = kk.kamar_id)
					JOIN pelayanan pel ON (pel.id = kmr.pelayanan_id)
				WHERE
					pel.jenis = 'RAWAT JALAN'
					$where
				GROUP BY
					kk.cara_bayar
				ORDER BY
					kk.cara_bayar
				";
			$kon->sql = $sql;
			$kon->execute();
			$baru[$i] = $kon->getAll();
		}
		$_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar][title] = $title . "\nPeriode " . tanggalIndo($tgl_start, "j F Y") . " s.d. " . tanggalIndo($tgl_end, "j F Y");
		$labelx = @array_unique($label_x);
		$_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar][label_x] = @implode(", ",$labelx);
		
		$new = array();
		for($i=0;$i<sizeof($baru);$i++) {
			for($s=0;$s<sizeof($baru[$i]);$s++) {
				$new[jml][$baru[$i][$s][nama]][$i] = $baru[$i][$s][jml];
			}
		}
		$table = new Table;
		$table->scroll = false;
		$table->addExtraTh("style=\"width:300px;\"");
		$table->Th[0][] = "Cara Pembayaran/ Periode";
		$table->Th[1][] = "1";
		for($i=0;$i<=$selisih;$i++) {
			$table->Th[0][] = $data[$i][tgl_periksa];
			$table->Th[1][] = ($i+2);
		}
		$_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar][th_0] = $table->Th[0];
		$_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar][th_1] = $table->Th[1];
		$cb = array('UMUM','JAMSOSTEK','DANA REKSA DESA','KONTRAK','LAIN-LAIN','ASKES');

		for($i=0;$i<sizeof($cb);$i++) {
			$table->Row[$i][] = $cb[$i];
			$_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar][cb][$i] = $cb[$i];
			for($s=0;$s<=$selisih;$s++) {
				if(!$new[jml][$cb[$i]][$s]) $new[jml][$cb[$i]][$s]=0;
				$table->Row[$i][] = $new[jml][$cb[$i]][$s];
				$_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar][jml][$i][] = $new[jml][$cb[$i]][$s];
			}
			$_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar][row][$i] = $table->Row[$i];
		}

		$ret = $table->build();
		$objResponse->addAssign("list_data", "innerHTML", $ret);
		$_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar][graph] = "<img src=\"" . URL . "rekmed/rekap_kunjungan_rajal_per_cara_bayar_graph_line/?md5=".md5(date("Ymdhis"))."\" alt=\"Kunjungan\" />";
		$_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar][title] = $title;
		$objResponse->addAssign("title", "innerHTML", nl2br($_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar][title]));
		$objResponse->addAssign("graph", "innerHTML", $_SESSION[rekmed][rekap_kunjungan_rajal_per_cara_bayar][graph]);
		return $objResponse;
	}
예제 #7
0
            // Number of full hours
            $datediff = floor($difference / 3600);
            break;
        case "n":
            // Number of full minutes
            $datediff = floor($difference / 60);
            break;
        default:
            // Number of full seconds (default)
            $datediff = $difference;
            break;
    }
    return $datediff;
}
// getting Date difference in SECONDS
$diff = datediff("s", $count_from, $countdown_to);
?>
// Here's where the Javascript starts
countdown = <?php 
echo $diff;
?>
;

// Converting date difference from seconds to actual time
function convert_to_time(secs)
{
	secs = parseInt(secs);	
	hh = secs / 3600;	
	hh = parseInt(hh);	
	mmt = secs - (hh * 3600);	
	mm = mmt / 60;	
예제 #8
0
	function get_kunjungan($val) {
		unset($_SESSION[ranap][statistik_kunjungan_ranap]);
		$tgl_start = @date("Y-m-d", @mktime(1,1,1,$val[tgl_periksa_bln_start], $val[tgl_periksa_tgl_start], $val[tgl_periksa_thn_start]));
		$tgl_end = @date("Y-m-d", @mktime(1,1,1,$val[tgl_periksa_bln_end], $val[tgl_periksa_tgl_end], $val[tgl_periksa_thn_end]));
		$title = "Statistik Kunjungan Rawat Inap";
		$objResponse = new xajaxResponse();
		$kon = new Konek;
		if($_SESSION[pelayanan_id]) {
			$kon->sql = "SELECT nama FROM pelayanan WHERE id = '".$_SESSION[pelayanan_id]."'";
			$kon->execute();
			$poli = $kon->getOne();
			$title .= "\nBangsal " . $poli[nama];
			$q = "AND pel.id = '".$_SESSION[pelayanan_id]."'";
		}
		if($val[tampilkan] == "hari") {
			$selisih = datediff('d', $tgl_start, $tgl_end);
			$tanggal_awal = tanggalIndo($tgl_start, "j F Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "j F Y");
		} elseif($val[tampilkan] == "bulan") {
			$selisih = datediff('m', $tgl_start, $tgl_end);
			$tanggal_awal = tanggalIndo($tgl_start, "F Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "F Y");
		} else {
			$selisih = datediff('y', $tgl_start, $tgl_end);
			$tanggal_awal = tanggalIndo($tgl_start, "Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "Y");
		}

		$title .= "\nPeriode " . $tanggal_awal . " s.d. " . $tanggal_akhir;

		$arr_tgl_start = explode("-",$tgl_start);
		$tgl_start_tgl = $arr_tgl_start[2];
		$tgl_start_bln = $arr_tgl_start[1];
		$tgl_start_thn = $arr_tgl_start[0];

		$arr_tgl_end = explode("-",$tgl_end);
		$tgl_end_tgl = $arr_tgl_end[2];
		$tgl_end_bln = $arr_tgl_end[1];
		$tgl_end_thn = $arr_tgl_end[0];

		
		for($i=0;$i<=$selisih;$i++) {
			if($val[tampilkan] == "hari") {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, $tgl_start_bln, ($i+$tgl_start_tgl), $tgl_start_thn));
				$tgl_periksa[$i] = tanggalIndo($tgl[$i], "j M\nY");
				$_SESSION[ranap][statistik_kunjungan_ranap][label_tick][$i] = @date("j", @mktime(1, 1, 1,$tgl_start_bln, ($tgl_start_tgl+$i), $tgl_start_thn));
				$label_x[$i] = @date("M Y", @mktime(1, 1, 1, $tgl_start_bln, ($tgl_start_tgl+$i), $tgl_start_thn));
				$where = " AND DATE(kk.tgl_periksa) = '" . $tgl[$i] . "' ";
				$where_keluar = " AND DATE(kk.tgl_keluar) = '" . $tgl[$i] . "' ";
			} elseif($val[tampilkan] == "bulan") {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$tgl_periksa[$i] = tanggalIndo($tgl[$i], "M\nY");
				$_SESSION[ranap][statistik_kunjungan_ranap][label_tick][$i] = @date("M y", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$label_x[$i] = @date("Y", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$where = " AND EXTRACT(YEAR_MONTH FROM kk.tgl_periksa) = EXTRACT(YEAR_MONTH FROM '" . $tgl[$i] . "') ";
				$where_keluar = " AND EXTRACT(YEAR_MONTH FROM kk.tgl_keluar) = EXTRACT(YEAR_MONTH FROM '" . $tgl[$i] . "') ";
			} else {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, 1, 1, ($tgl_start_thn + $i)));
				$tgl_periksa[$i] = tanggalIndo($tgl[$i], "Y");
				$_SESSION[ranap][statistik_kunjungan_ranap][label_tick][$i] = @date("Y", @mktime(1, 1, 1, 1, 1, ($tgl_start_thn+$i)));
				$label_x[$i] = "Tahun";
				$where = " AND YEAR(kk.tgl_periksa) = YEAR('" . $tgl[$i] . "') ";
				$where_keluar = " AND YEAR(kk.tgl_keluar) = YEAR('" . $tgl[$i] . "') ";
			}
			
			$sql = "
				SELECT
					COUNT(kk.id) as jml
				FROM
					kunjungan_kamar kk 
					JOIN kunjungan k ON (k.id = kk.kunjungan_id)
					JOIN pasien p ON (p.id = k.pasien_id)
					JOIN kamar kmr ON (kmr.id = kk.kamar_id)
					JOIN pelayanan pel ON (pel.id = kmr.pelayanan_id)
				WHERE
					pel.jenis = 'RAWAT INAP'
					$q
					$where
				";
			$kon->sql = $sql;
			$kon->execute();
			$masuk[$i] = $kon->getOne();
			if(!$masuk[$i][jml]) $masuk[$i][jml] = 0;

			$_SESSION[ranap][statistik_kunjungan_ranap][jml_masuk][$i] = $masuk[$i][jml];
			$_SESSION[ranap][statistik_kunjungan_ranap][tgl_periksa][$i] = $tgl_periksa[$i];
			

			//GET DATA PX KELUAR
			$sql2 = "
				SELECT
					COUNT(kk.id) as jml
				FROM
					kunjungan_kamar kk 
					JOIN kunjungan k ON (k.id = kk.kunjungan_id)
					JOIN pasien p ON (p.id = k.pasien_id)
					JOIN kamar kmr ON (kmr.id = kk.kamar_id)
					JOIN pelayanan pel ON (pel.id = kmr.pelayanan_id)
				WHERE
					pel.jenis = 'RAWAT INAP'
					$q
					$where_keluar
				";
			$kon->sql = $sql2;
			$kon->execute();
			$keluar[$i] = $kon->getOne();
			if(!$keluar[$i][jml]) $keluar[$i][jml] = 0;

			$_SESSION[ranap][statistik_kunjungan_ranap][jml_keluar][$i] = $keluar[$i][jml];

		}
		//$objResponse->addAlert(print_r($lama));
		$_SESSION[ranap][statistik_kunjungan_ranap][title] = $title . "\nPeriode " . tanggalIndo($tgl_start, "j F Y") . " s.d. " . tanggalIndo($tgl_end, "j F Y");
		$labelx = @array_unique($label_x);
		$_SESSION[ranap][statistik_kunjungan_ranap][label_x] = @implode(", ",$labelx);

		$table = new Table;
		$table->scroll = false;
		for($i=0;$i<=$selisih;$i++) {
			$table->Th[0][] = $tgl_periksa[$i];
			$table->extra_th[0][] = "colspan=\"2\"";
			$table->Row[0][$i*2] = $masuk[$i][jml];
			$table->Row[0][$i*2+1] = $keluar[$i][jml];	
		}
		for($i=0;$i<=($selisih*2+1);$i++) {
			$x = $i;
			if($i % 2 == 0) {
				$table->Th[1][] = "Masuk";
			} else {
				$table->Th[1][] = "Keluar";
			}
			$table->Th[2][] = ($i+1);		
		}
		$ret = $table->build();

		$_SESSION[ranap][statistik_kunjungan_ranap][th_0] = $table->Th[0];
		$_SESSION[ranap][statistik_kunjungan_ranap][th_1] = $table->Th[1];
		$_SESSION[ranap][statistik_kunjungan_ranap][extra_th_0] = $table->extra_th[0];
		$_SESSION[ranap][statistik_kunjungan_ranap][row] = $table->Row[0];
		
		$objResponse->addAssign("list_data", "innerHTML", $ret);
		$_SESSION[ranap][statistik_kunjungan_ranap][graph] = "<img src=\"" . URL . "ranap/statistik_kunjungan_ranap_graph_bar/?md5=".md5(date("Ymdhis"))."\" alt=\"Kunjungan\" />";
		$_SESSION[ranap][statistik_kunjungan_ranap][title] = $title;
		$objResponse->addAssign("title", "innerHTML", nl2br($_SESSION[ranap][statistik_kunjungan_ranap][title]));
		$objResponse->addAssign("graph", "innerHTML", $_SESSION[ranap][statistik_kunjungan_ranap][graph]);
		return $objResponse;
	}
예제 #9
0
파일: list_loan.php 프로젝트: k9ert/ac4ngos
echo get_month_name($ref_date) . " " . get_year($ref_date) . "</div>";
if ($type == "PF") {
    $loan_table = "PF_LOAN";
} else {
    if ($type == "CUF") {
        $loan_table = "CUF_LOAN";
    } else {
        die("Loantype unspecified !");
    }
}
$result = mysql_query("select * from {$loan_table}", $db);
checkMySQLError();
beginPrettyTable("4", "{$loan_table}");
printRow(array("Emp_ID3", "Emp. Name", "LoanStart", "LoanEnd", "Loan-Amt", "Instalment", "Tot_Amt", "Due", "Balance"));
while ($row = mysql_fetch_array($result)) {
    $name = $personal_array[$row["EMP_ID3"]];
    $rest_inst_no = datediff("m", $ref_date, $row["LOAN_END"]);
    $rest_amount = $rest_inst_no * $row["INT_RATE"];
    if ($rest_inst_no < 0) {
        continue;
    }
    $inst_sum += $rest_inst_no;
    $rest_amount_sum += $rest_amount;
    $loan_amount_sum += $row["LOAN_AMT"];
    printRow(array($row["EMP_ID3"], $name, conv_to_hrd($row["LOAN_START"]), conv_to_hrd($row["LOAN_END"]), $row["LOAN_AMT"], $row["INT_RATE"], $row["TOT_AMT"], $rest_inst_no, $rest_amount), "fluct");
}
printRow(array("", "", "Loan-Amt-Sum: ", $loan_amount_sum), "", "3,2");
printRow(array("", "", "Inst-Sum: ", "", $inst_sum), "", "3,2");
printRow(array("", "", "Balance-Sum: ", "", "", "", "", $rest_amount_sum), "", "3,2");
endPrettyTable();
endDocument();
예제 #10
0
 public function Subcription($frequency, $start, $end, $due)
 {
     //helper function
     function datediff($interval, $datefrom, $dateto, $using_timestamps = false)
     {
         /*
         $interval can be:
         yyyy - Number of full years
         q - Number of full quarters
         m - Number of full months
         y - Difference between day numbers
             (eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
         d - Number of full days
         w - Number of full weekdays
         ww - Number of full weeks
         h - Number of full hours
         n - Number of full minutes
         s - Number of full seconds (default)
         */
         if (!$using_timestamps) {
             $datefrom = strtotime($datefrom, 0);
             $dateto = strtotime($dateto, 0);
         }
         $difference = $dateto - $datefrom;
         // Difference in seconds
         switch ($interval) {
             case 'yyyy':
                 // Number of full years
                 $years_difference = floor($difference / 31536000);
                 if (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom), date("j", $datefrom), date("Y", $datefrom) + $years_difference) > $dateto) {
                     $years_difference--;
                 }
                 if (mktime(date("H", $dateto), date("i", $dateto), date("s", $dateto), date("n", $dateto), date("j", $dateto), date("Y", $dateto) - ($years_difference + 1)) > $datefrom) {
                     $years_difference++;
                 }
                 $datediff = $years_difference;
                 break;
             case "q":
                 // Number of full quarters
                 $quarters_difference = floor($difference / 8035200);
                 while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom) + $quarters_difference * 3, date("j", $dateto), date("Y", $datefrom)) < $dateto) {
                     $months_difference++;
                 }
                 $quarters_difference--;
                 $datediff = $quarters_difference;
                 break;
             case "m":
                 // Number of full months
                 $months_difference = floor($difference / 2678400);
                 while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom) + $months_difference, date("j", $dateto), date("Y", $datefrom)) < $dateto) {
                     $months_difference++;
                 }
                 $months_difference--;
                 $datediff = $months_difference;
                 break;
             case 'y':
                 // Difference between day numbers
                 $datediff = date("z", $dateto) - date("z", $datefrom);
                 break;
             case "d":
                 // Number of full days
                 $datediff = floor($difference / 86400);
                 break;
             case "w":
                 // Number of full weekdays
                 $days_difference = floor($difference / 86400);
                 $weeks_difference = floor($days_difference / 7);
                 // Complete weeks
                 $first_day = date("w", $datefrom);
                 $days_remainder = floor($days_difference % 7);
                 $odd_days = $first_day + $days_remainder;
                 // Do we have a Saturday or Sunday in the remainder?
                 if ($odd_days > 7) {
                     // Sunday
                     $days_remainder--;
                 }
                 if ($odd_days > 6) {
                     // Saturday
                     $days_remainder--;
                 }
                 $datediff = $weeks_difference * 5 + $days_remainder;
                 break;
             case "ww":
                 // Number of full weeks
                 $datediff = floor($difference / 604800);
                 break;
             case "h":
                 // Number of full hours
                 $datediff = floor($difference / 3600);
                 break;
             case "n":
                 // Number of full minutes
                 $datediff = floor($difference / 60);
                 break;
             default:
                 // Number of full seconds (default)
                 $datediff = $difference;
                 break;
         }
         return $datediff;
     }
     $fmt = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
     switch ($frequency) {
         case 1:
             //Weekly
             $frequency = Frequency::find($frequency)->name;
             $recurrences = datediff("ww", $start, $end, false);
             $schedule = array();
             for ($x = 0; $x <= $recurrences; $x++) {
                 $schedule[] = Carbon::createFromTimestamp(strtotime($start))->addWeeks($x)->format('m/d/y ');
             }
             $recurrences = $x;
             $amount = $fmt->parse($due) / $x;
             break;
         case 2:
             //Every two weeks
             $frequency = Frequency::find($frequency)->name;
             $recurrences = round(datediff("ww", $start, $end, false)) / 2;
             $schedule = array();
             for ($x = 0; $x <= $recurrences; $x++) {
                 $schedule[] = Carbon::createFromTimestamp(strtotime($start))->addWeeks($x * 2)->format('m/d/y ');
             }
             $recurrences = $x;
             $amount = $fmt->parse($due) / $x;
             break;
         case 3:
             //Monthly
             $frequency = Frequency::find($frequency)->name;
             $recurrences = datediff("m", $start, $end, false);
             $schedule = array();
             for ($x = 0; $x <= $recurrences; $x++) {
                 $schedule[] = Carbon::createFromTimestamp(strtotime($start))->addMonths($x)->format('m/d/y ');
             }
             $recurrences = $x;
             $amount = $fmt->parse($due) / $x;
             break;
     }
     setlocale(LC_MONETARY, "en_US");
     $result = array("frequency" => $frequency, "start" => $start, "end" => $end, "subtotal" => money_format('%.2n', round($amount, 2)), "fee" => money_format('%.2n', round($amount / getenv("SV_FEE") - $amount, 2)), "total" => money_format('%.2n', round($amount / getenv("SV_FEE"), 2)), "recurrences" => $recurrences, "dates" => $schedule);
     $object = json_decode(json_encode($result), FALSE);
     return $object;
 }
예제 #11
0
<?php 
$r1 = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT count(id) as cnt from " . $tablename . " where vote=1  and date(contactdate) ='" . $date2 . "' and userid !=0"));
$r2 = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT count(id) as cnt from " . $tablename . " where vote=0 and date(contactdate) ='" . $date2 . "' and userid !=0 and iscalled=1"));
$r3 = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT count(id) as cnt from " . $tablename . " where vote=2 and date(contactdate) ='" . $date2 . "' and userid !=0"));
$r4 = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT count(id) as cnt from " . $tablename . " where iscalled=2 and date(contactdate) ='" . $date2 . "'"));
$r5 = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT count(id) as cnt from " . $tablename . " where iscalled=3 and date(contactdate) ='" . $date2 . "'"));
$r6 = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT count(id) as cnt from " . $tablename . " where iscalled=4 and date(contactdate) ='" . $date2 . "'"));
$r7 = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT count(id) as cnt from " . $tablename . " where iscalled=5 and date(contactdate) ='" . $date2 . "'"));
?>
</td>
  </tr>
</table>
   
<br />
 <?php 
$datediffno = datediff($date2, $date1);
if ($datediffno <= 0) {
    ?>
                  <p class="norecords">No Contacts <?php 
    if ($action == "show") {
        echo ' with this filter.';
    }
    ?>
</p>

<?php 
} else {
    ?>
<table class="table table-hover  table_vam table-black" width="400">
    	<thead>
        <tr>
예제 #12
0
파일: fun.php 프로젝트: autotel/taskstack
date_default_timezone_set("America/Santiago");
$today = date("Y-m-d H:i:s");
//pendiente: cambiar a unix
//echo "<p style=\"position:absolute\">system date is $today</p>";
include "common_funcs_php.php";
$extraclass = "";
worDB();
$sql = "SELECT tid, content, context, user, deadline, importance, submission_date, status\n\t\tFROM taskstack\n\t\tWHERE context='lectura' OR context='peliculas' OR context='entretencion' OR context='BDE'";
mysql_select_db($db);
$retval = mysql_query($sql, $conn);
$printarray = array();
if (!$retval) {
    die('Could not get data: ' . mysql_error());
} else {
    while ($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
        $ddiff = floatval(datediff($today, $row["deadline"], "\$d"));
        //$ddiff+=1;
        $extraclass = "";
        if ($today . "" === $row['deadline']) {
            $extraclass = " today";
        }
        if ($tomorrow . "" === $row['deadline']) {
            $extraclass = " tomorrow";
        }
        if ("ready" === $row['status']) {
            $extraclass .= " ready";
        }
        $extraclass .= " im" . $row['importance'];
        $printarray[$row['importance'] . "x" . $row['deadline'] . "x" . $row['tid']] = '<div data-datediff="' . $ddiff . '" data-tid="' . $row['tid'] . '" data-context="' . $row['context'] . '" class="item ' . $extraclass . '">' . "<b>{$row['context']}</b><BR>" . "{$row['content']}<br><a class=\"ajax\" href=\"{$_SERVER['self']}input.php?actionload=true&tid={$row['tid']}\">edit</a>";
        if ($row['status'] === "ready") {
            $printarray[$row['importance'] . "x" . $row['deadline'] . "x" . $row['tid']] .= "" . " | <a class=\"ajax\" href=\"{$_SERVER['self']}postExec.php?action=remove&tid={$row['tid']}\">remove</a>";
예제 #13
0
if ($thn[0] != $thn2[0]) {
    exit("Error:Tahun tidak boleh beda");
}
//echo $sistemGaji;
$tanggal1 = $tgl1 . "-01";
$tanggal2 = $tgl2 . "-01";
function datediff($tgl1, $tgl2)
{
    $tgl1 = strtotime($tgl1);
    $tgl2 = strtotime($tgl2);
    $diff_secs = abs($tgl1 - $tgl2);
    $base_year = min(date("Y", $tgl1), date("Y", $tgl2));
    $diff = mktime(0, 0, $diff_secs, 1, 1, $base_year);
    return array("years" => date("Y", $diff) - $base_year, "months_total" => (date("Y", $diff) - $base_year) * 12 + date("n", $diff) - 1, "months" => date("n", $diff) - 1, "days_total" => floor($diff_secs / (3600 * 24)), "days" => date("j", $diff) - 1, "hours_total" => floor($diff_secs / 3600), "hours" => date("G", $diff), "minutes_total" => floor($diff_secs / 60), "minutes" => (int) date("i", $diff), "seconds_total" => $diff_secs, "seconds" => (int) date("s", $diff));
}
$totBln = datediff($tanggal1, $tanggal2);
//exit("error".$totBln[months_total]);
for ($ard = 1; $ard <= $totBln['months_total']; $ard++) {
    if (strlen($ard) < 2) {
        $bar = "0" . $ard;
    }
    $test[] = $thn1[0] . "-" . $bar;
}
//ambil query untuk data karyawan
if ($kdOrg != '') {
    $kodeOrg = $kdOrg;
    if ($_SESSION['empl']['tipelokasitugas'] == 'HOLDING') {
        $where = "  lokasitugas in ('" . $kodeOrg . "')";
    } else {
        if (strlen($kdOrg) > 4) {
            $where = "  subbagian='" . $kdOrg . "'";
        $resptime = $row_01['responding'];
        $resp_list[$row_01['id']] = datediff($resptime, $disptime);
    }
}
//	Average time Dispatched to On Scene
$query = "SELECT *, `{$GLOBALS['mysql_prefix']}ticket`.`id` AS `tick_id`\n\t\tFROM `{$GLOBALS['mysql_prefix']}ticket` \n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}allocates` \n\t\t\tON `{$GLOBALS['mysql_prefix']}ticket`.`id`=`{$GLOBALS['mysql_prefix']}allocates`.`resource_id`\n\t\tWHERE (`status` = 2 or `status` = 3) {$where2} {$where2} AND `{$GLOBALS['mysql_prefix']}allocates`.`type` = 1 GROUP BY `tick_id`";
$result = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
$num_tick3 = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
    $tick_id = $row['tick_id'];
    $query_01 = "SELECT *,\n\t\t\t\tUNIX_TIMESTAMP(`{$GLOBALS['mysql_prefix']}assigns`.`dispatched`) as `dispatched`,\n\t\t\t\tUNIX_TIMESTAMP(`{$GLOBALS['mysql_prefix']}assigns`.`responding`) as `responding`,\t\t\t\t\n\t\t\t\tUNIX_TIMESTAMP(`{$GLOBALS['mysql_prefix']}assigns`.`on_scene`) as `on_scene`\t\t\t\t\n\t\t\t\tFROM `{$GLOBALS['mysql_prefix']}assigns` \n\t\t\t\tWHERE `ticket_id` = {$tick_id} AND (`on_scene` IS NOT NULL OR DATE_FORMAT(`on_scene`,'%y') != '00')";
    $result_01 = mysql_query($query_01) or do_error($query_01, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
    while ($row_01 = mysql_fetch_assoc($result_01)) {
        $disptime = $row_01['dispatched'];
        $ostime = $row_01['on_scene'];
        $os_list[$row_01['id']] = datediff($ostime, $disptime);
    }
}
// Number of responders not assigned and Available
$x = 0;
$where2 = "WHERE (";
foreach ($al_groups as $grp) {
    $where3 = count($al_groups) > $x + 1 ? " OR " : ")";
    $where2 .= "`{$GLOBALS['mysql_prefix']}allocates`.`group` = '{$grp}'";
    $where2 .= $where3;
    $x++;
}
$query = "SELECT *,\t`{$GLOBALS['mysql_prefix']}responder`.`id` AS `resp_id`,\n\t\t(SELECT  COUNT(*) as numfound FROM `{$GLOBALS['mysql_prefix']}assigns` \n\t\t\tWHERE `{$GLOBALS['mysql_prefix']}assigns`.`responder_id` = `{$GLOBALS['mysql_prefix']}responder`.`id`  \n\t\t\tAND `clear` IS NULL OR DATE_FORMAT(`clear`,'%y') = '00' ) \n\t\t\tAS `num_assignments`\n\t\tFROM `{$GLOBALS['mysql_prefix']}responder`\t\t\t\n\t\tLEFT JOIN `{$GLOBALS['mysql_prefix']}allocates` \n\t\t\tON `{$GLOBALS['mysql_prefix']}responder`.id=`{$GLOBALS['mysql_prefix']}allocates`.`resource_id`\t\n\t\t {$where2} AND `{$GLOBALS['mysql_prefix']}allocates`.`type` = 2 GROUP BY `{$GLOBALS['mysql_prefix']}responder`.`id`";
$result = mysql_query($query) or do_error($query, 'mysql query failed', mysql_error(), basename(__FILE__), __LINE__);
while ($row = mysql_fetch_assoc($result)) {
    if ($row['num_assignments'] == 0) {
예제 #15
0
function icon_new($orm)
{
    if (datediff($orm->start_date) >= -5) {
        return '<img src="themes/gcdnew/images/new_icon.png" style="float:none; padding:0; border:none;" alt="บทความใหม่" />';
    }
}
예제 #16
0
         //calculate if this payment applies to each date column
         $col_date = date("w", strtotime("+" . $date . " day", strtotime($date_today)));
         if ($col_date == $data["payment_dayofweek"]) {
             $cashflow_row[] = $data["payment_value"];
         } else {
             $cashflow_row[] = 0;
         }
     }
     break;
 case 2:
     // 2. Fortnightly = Start date: 21 Feb 2016
     for ($date = 0; $date <= $numdata_cols; $date++) {
         //calculate if this payment applies to each date column
         $col_day = $daysoffortnight[date("w", strtotime("+" . $date . " day", strtotime($date_today)))];
         $col_date = date("j F Y", strtotime("+" . $date . " day", strtotime($date_today)));
         if (datediff('ww', '3 January 2016', $col_date, false) & 1) {
             $iswk2 = "";
         } else {
             $iswk2 = "-wk2";
         }
         if ($col_day . $iswk2 == $daysoffortnight[$data["payment_dayoffortnight"]]) {
             $cashflow_row[] = $data["payment_value"];
         } else {
             $cashflow_row[] = 0;
         }
     }
     break;
 case 3:
     // Monthly = 	Day of Month: 21 (up to 28 to avoid Feb issues)
     for ($date = 0; $date <= $numdata_cols; $date++) {
         //calculate if this payment applies to each date column
예제 #17
0
function getStyledDateDiff($datefrom, $dateto, $using_timestamps = false)
{
    global $treng;
    $mindiff = datediff('n', $datefrom, $dateto, $using_timestamps);
    $hourdiff = floor($mindiff / 60);
    $mindiff %= 60;
    $daydiff = floor($hourdiff / 24);
    $hourdiff %= 24;
    $monthdiff = floor($daydiff / 30);
    $daydiff %= 30;
    $yeardiff = floor($monthdiff / 12);
    $yeardiff %= 12;
    if ($yeardiff > 2) {
        return !isset($treng) ? $yeardiff . " years ago" : sprintf($treng->_("%s years ago", "genfuns"), $yeardiff);
    } elseif ($yeardiff > 0) {
        if ($yeardiff * 12 + $monthdiff == 1) {
            return !isset($treng) ? $yeardiff * 12 + $monthdiff . " month ago" : sprintf($treng->_("%s month ago", "genfuns"), $yeardiff * 12 + $monthdiff);
        } else {
            return !isset($treng) ? $yeardiff * 12 + $monthdiff . " months ago" : sprintf($treng->_("%s months ago", "genfuns"), $yeardiff * 12 + $monthdiff);
        }
    } elseif ($monthdiff > 2) {
        if ($monthdiff == 1) {
            return !isset($treng) ? $monthdiff . " month ago" : sprintf($treng->_("%s month ago", "genfuns"), $monthdiff);
        } else {
            return !isset($treng) ? $monthdiff . " months ago" : sprintf($treng->_("%s months ago", "genfuns"), $monthdiff);
        }
    } elseif ($monthdiff != 0 || $daydiff != 0) {
        if ($monthdiff * 30 + $daydiff == 1) {
            return !isset($treng) ? $monthdiff * 30 + $daydiff . " day ago" : sprintf($treng->_("%s days ago", "genfuns"), $monthdiff * 30 + $daydiff);
        } else {
            return !isset($treng) ? $monthdiff * 30 + $daydiff . " days ago" : sprintf($treng->_("%s days ago", "genfuns"), $monthdiff * 30 + $daydiff);
        }
    } elseif ($hourdiff != 0) {
        if ($hourdiff == 1) {
            return !isset($treng) ? $hourdiff . " hour ago" : sprintf($treng->_("%s hour ago", "genfuns"), $hourdiff);
        } else {
            return !isset($treng) ? $hourdiff . " hours ago" : sprintf($treng->_("%s hours ago", "genfuns"), $hourdiff);
        }
    } else {
        if ($mindiff == 1) {
            return !isset($treng) ? $mindiff . " minute ago" : sprintf($treng->_("%s minute ago", "genfuns"), $mindiff);
        } else {
            return !isset($treng) ? $mindiff . " minutes ago" : sprintf($treng->_("%s minutes ago", "genfuns"), $mindiff);
        }
    }
}
예제 #18
0
include "../include/conn.php";
include "../include/function.php";
include "../include/periodscls.php";
include "../include/datecls.php";
if ($action == "addperiods") {
    $hint = "";
    if (trim($begindate) == "") {
        $hint .= "请选择开始日期\\n";
    }
    if (trim($enddate) == "") {
        $hint .= "请选择结束日期\\n";
    }
    $periods = getperiods1() + 1;
    $begintime = strtotime(trim($begindate));
    $endtime = strtotime(trim($enddate));
    $c = datediff($begindate, $enddate);
    $sql = "select * from {$db_prefix}periods1 where begintime='{$begintime}' and endtime='{$endtime}' ";
    $rs = $db->get_one($sql);
    if (!empty($rs)) {
        $hint = "请勿重复添加结算!";
    }
    $sql = "select * from {$db_prefix}periods1 where ('{$begintime}'>=begintime and '{$begintime}'<=endtime) or ('{$endtime}'>=begintime and '{$endtime}'<=endtime)";
    $rs = $db->get_one($sql);
    if (!empty($rs)) {
        $hint = "结算日期重复!请重新添加。";
    }
    if (!empty($year)) {
        if (strlen($month) != 2) {
            $hint = "请输入正确的月格式";
        }
    }
예제 #19
0
echo "<thread> <tr>\n\t\t<th scope='col'>\n\t\t<a class='novisit' href=\"" . $_SERVER['PHP_SELF'] . "?orderBy=username&orderType={$orderTypeNextPage}\">\n\t\t" . $l['all']['Username'] . "</a>\n\t\t</th>\n\t\t<th scope='col'>\n\t\t<a class='novisit' href=\"" . $_SERVER['PHP_SELF'] . "?orderBy=attribute&orderType={$orderTypeNextPage}\">\n\t\t" . $l['all']['Attribute'] . "</a>\n\t\t</th>\n\t\t<th scope='col'>\n\t\t<a class='novisit' href=\"" . $_SERVER['PHP_SELF'] . "?orderBy=maxtimeexpiration&orderType={$orderTypeNextPage}\">\n\t\t" . $l['all']['MaxTimeExpiration'] . "</a>\n\t\t</th>\n\t\t<th scope='col'>\n\t\t<a class='novisit' href=\"" . $_SERVER['PHP_SELF'] . "?orderBy=usedtime&orderType={$orderTypeNextPage}\">\n\t\t" . $l['all']['UsedTime'] . "</a>\n\t\t</th>\n\t\t<th scope='col'> " . $l['all']['Status'] . " </th>\n\t\t<th scope='col'> " . $l['all']['Usage'] . " </th>\n\t\t</tr> </thread>";
while ($row = $res->fetchRow()) {
    $status = "Active";
    if ($row[1] == "Expiration") {
        if (datediff('d', $row[2], "{$currdate}", false) > 0) {
            $status = "Expired";
        }
    }
    if ($row[1] == "Max-All-Session") {
        if ($row[3] >= $row[2]) {
            $status = "End";
        }
    }
    printqn("<tr>\n                        <td> <a class='tablenovisit' href='javascript:return;'\n                                onClick='javascript:ajaxGeneric(\"include/management/retUserInfo.php\",\"retBandwidthInfo\",\"divContainerUserInfo\",\"username={$row['0']}\");\n                                        javascript:__displayTooltip();'\n                                tooltipText='\n                                        <a class=\"toolTip\" href=\"mng-edit.php?username={$row['0']}\">\n                                                {$l['Tooltip']['UserEdit']}</a>\n                                        <br/><br/>\n\n                                        <div id=\"divContainerUserInfo\">\n                                                Loading...\n                                        </div>\n                                        <br/>'\n                                >{$row['0']}</a>\n                        </td>\n\n                        <td> {$row['1']} </td>\n                        <td> {$row['2']} </td>\n                        <td>" . time2str($row[3]) . "</td>\n                        <td> {$status} </td>\n\t\t\t<td> ");
    if ($row[1] == "Expiration") {
        $difference = datediff('d', $row[2], "{$currdate}", false);
        if ($difference > 0) {
            echo "<h100> " . " {$difference} days since expired" . "</h100> ";
        } else {
            echo substr($difference, 1) . " days until expiration";
        }
    }
    if ($row[1] == "Max-All-Session") {
        if ($status == "End") {
            echo "<h100> " . abs($row[2] - $row[3]) . " seconds overdue credit" . "</h100>";
        } else {
            echo $row[2] - $row[3];
            echo " left on credit";
        }
    }
    echo "\t</td>\n                </tr>";
예제 #20
0
파일: fungsi.php 프로젝트: reekoheek/srmis
	function hariIni($tgl, $tgl_sekarang = null) {
      if($tgl_sekarang == null) {
         $tgl_sekarang = date("Y-m-d");
      }
      $selisih = datediff("d", $tgl_sekarang, $tgl);
      if($selisih == 0) $ret = "Hari Ini";
      elseif($selisih == 1) $ret = "Kemarin";
      elseif($selisih == 2) $ret = "Kemarin Lusa";
      else $ret = tanggalIndo($tgl, "j M Y");
      return $ret;
   }
 /**
  * Run the Google SiteMap XML generation, recursively
  *
  * @param int $currentParent The current parent resource the iteration
  * is on
  * @param int $selfId If specified, will exclude this ID
  * @param int $depth
  * @return string The generated XML
  */
 public function run($currentParent, $selfId = -1, $depth = 0)
 {
     if (!empty($this->config['maxDepth']) && $depth >= $this->config['maxDepth']) {
         return '';
     }
     $output = '';
     /* get children */
     $c = $this->getQuery($currentParent);
     $children = $this->modx->getCollection('modResource', $c);
     /** @var modResource $child */
     foreach ($children as $child) {
         $id = $child->get('id');
         if ($selfId == $id) {
             continue;
         }
         $canParse = true;
         if ($this->config['searchable']) {
             $canParse = $canParse && $child->get('searchable');
         }
         if ($this->config['published']) {
             $canParse = $canParse && $child->get('published');
         }
         if ($this->config['hideDeleted']) {
             $canParse = $canParse && !$child->get('deleted');
         }
         if (empty($this->config['showHidden'])) {
             $canParse = $canParse && (!$child->get('hidemenu') || $child->get('class_key') == 'Article');
         }
         if ($canParse) {
             $url = $this->modx->makeUrl($id, '', '', 'full');
             $date = $child->get('editedon') ? $child->get('editedon') : $child->get('createdon');
             $date = date("Y-m-d", strtotime($date));
             /* Get the date difference */
             $datediff = datediff("d", $date, date("Y-m-d"));
             if ($datediff <= 1) {
                 $priority = '1.0';
                 $update = 'daily';
             } elseif ($datediff > 1 && $datediff <= 7) {
                 $priority = '0.75';
                 $update = 'weekly';
             } elseif ($datediff > 7 && $datediff <= 30) {
                 $priority = '0.50';
                 $update = 'weekly';
             } else {
                 $priority = '0.25';
                 $update = 'monthly';
             }
             if (!empty($this->config['priorityTV'])) {
                 $priorityTV = $child->getTVValue($this->config['priorityTV']);
                 if (!empty($priorityTV)) {
                     $priority = $priorityTV;
                 }
             }
             /* add item to output */
             $output .= $this->getChunk($this->config['itemTpl'], array('url' => $url, 'date' => $date, 'update' => $update, 'priority' => $priority)) . $this->config['itemSeparator'];
         }
         /* if children, recurse */
         if ($child->get('children') > 0) {
             $output .= $this->run($child->get('id'), $selfId, $depth + 1);
         }
     }
     return $output;
 }
예제 #22
0
 function shell($telegram, $db, $data, $text, $chat_id, $user_id, $location, $reply_to_msg)
 {
     date_default_timezone_set('Europe/Rome');
     $today = date("Y-m-d H:i:s");
     if ($text == "/start") {
         $log = $today . ",new chat started," . $chat_id . "\n";
     } elseif ($text == "uffici comunali") {
         $nome = $data->get_uffici();
         $option1 = explode("\n", $nome);
         if ($nome == "Non ci sono Settori") {
             $content = array('chat_id' => $chat_id, 'text' => $nome, 'disable_web_page_preview' => true);
         } else {
             //  $option = array($option1);
             $optionf = array([]);
             for ($i = 0; $i < count($option1) - 1; $i++) {
                 array_push($optionf, ["🏛 " . $option1[$i]]);
             }
             $keyb = $telegram->buildKeyBoard($optionf, $onetime = false);
             $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "[seleziona un Settore]");
         }
         $telegram->sendMessage($content);
         exit;
         //$log=$today. ",new chat started," .$chat_id. "\n";
     } elseif (strpos($text, '🏛') !== false) {
         $text = str_replace("🏛 ", "", $text);
         $reply = "Sto cercando l'ubicazione delle sedi: " . $text;
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $text = strtoupper($text);
         $text = str_replace(" ", "%20", $text);
         $reply1 = $data->get_sedi($text);
         $chunks = str_split($reply1, self::MAX_LENGTH);
         foreach ($chunks as $chunk) {
             $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         $log = $today . ",sedicomunali," . $chat_id . "\n";
     } elseif (strpos($text, '?') !== false) {
         $text = str_replace("?", "", $text);
         $img = curl_file_create('soldipubblici.png', 'image/png');
         $contentp = array('chat_id' => $chat_id, 'photo' => $img);
         $telegram->sendPhoto($contentp);
         sleep(1);
         $reply = "Interrogazione del Database di Soldipubblici.gov.it attendere....";
         $reply .= $data->get_spesecorrenti($text);
         $chunks = str_split($reply, self::MAX_LENGTH);
         foreach ($chunks as $chunk) {
             $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         $log = $today . ",spese correnti sent," . $chat_id . "\n";
     } elseif (strpos($text, '🚌') !== false) {
         $content = array('chat_id' => $chat_id, 'text' => "Attendere per favore..", 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $text = str_replace("🚌 ", "", $text);
         $text = str_replace("/", "", $text);
         $text = str_replace("___", "<", $text);
         $text = str_replace("__", "~", $text);
         $text = str_replace("_", "-", $text);
         date_default_timezone_set("Europe/Rome");
         $ora = date("H:i:s", time());
         $ora2 = date("H:i:s", time() + 60 * 60);
         $json_string = file_get_contents("https://transit.land/api/v1/onestop_id/" . $text);
         $parsed_json = json_decode($json_string);
         $count = 0;
         $countl = 0;
         $namedest = $parsed_json->{'name'};
         $IdFermata = "";
         foreach ($parsed_json->{'routes_serving_stop'} as $data => $csv1) {
             $count = $count + 1;
         }
         //  echo $count."/n";
         for ($i = 0; $i < $count; $i++) {
             $countl = 0;
             $json_string1 = file_get_contents("https://transit.land/api/v1/schedule_stop_pairs?destination_onestop_id=" . $text . "&origin_departure_between=" . $ora . "," . $ora2);
             $parsed_json1 = json_decode($json_string1);
             foreach ($parsed_json1->{'schedule_stop_pairs'} as $data12 => $csv11) {
                 $countl = $countl + 1;
             }
             $start = 0;
             if ($countl == 0) {
                 $content = array('chat_id' => $chat_id, 'text' => "Non ci sono arrivi nella prossima ora", 'disable_web_page_preview' => true);
                 $telegram->sendMessage($content);
                 $this->create_keyboard($telegram, $chat_id);
                 exit;
             } else {
                 $start = 1;
             }
             //echo $countl;
             $distanza = [];
             $json_string2 = file_get_contents("https://transit.land/api/v1/onestop_id/" . $parsed_json1->{'schedule_stop_pairs'}[$i]->{'origin_onestop_id'});
             $parsed_json2 = json_decode($json_string2);
             $name = $parsed_json2->{'name'};
             for ($l = 0; $l < $countl; $l++) {
                 //	if ( ($parsed_json1->{'schedule_stop_pairs'}[$l]->{'route_onestop_id'}) == $parsed_json->{'routes_serving_stop'}[$i]->{'route_onestop_id'})
                 //	{
                 $distanza[$l]['orari'] = $parsed_json1->{'schedule_stop_pairs'}[$l]->{'destination_arrival_time'};
                 //	}
             }
             sort($distanza);
             for ($l = 0; $l < $countl; $l++) {
                 if ($parsed_json1->{'schedule_stop_pairs'}[$l]->{'route_onestop_id'} == $parsed_json->{'routes_serving_stop'}[$i]->{'route_onestop_id'}) {
                     $temp_c1 .= "Linea: / Line:  " . $parsed_json->{'routes_serving_stop'}[$i]->{'route_name'} . " arrivo: / arrive:  ";
                     //    $temp_c1 .=$parsed_json1->{'schedule_stop_pairs'}[$l]->{'destination_arrival_time'};
                     $temp_c1 .= $distanza[$l]['orari'] . "\nproveniente da: / from:  " . $name;
                     $temp_c1 .= "\n";
                 }
             }
         }
         if ($start == 1) {
             $content = array('chat_id' => $chat_id, 'text' => "Linee in arrivo nella prossima ora a / incoming lines in the next hour to " . $namedest . "\n", 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         $chunks = str_split($temp_c1, self::MAX_LENGTH);
         foreach ($chunks as $chunk) {
             // $forcehide=$telegram->buildForceReply(true);
             //chiedo cosa sta accadendo nel luogo
             $content = array('chat_id' => $chat_id, 'text' => $chunk, 'reply_to_message_id' => $bot_request_message_id, 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         //$telegram->sendMessage($content);
         //	echo $temp_l1;
         //if ($temp_l1 ==="") {
         //	$content = array('chat_id' => $chat_id, 'text' => "Nessuna fermata nei paraggi", 'reply_to_message_id' =>$bot_request_message_id);
         //		$telegram->sendMessage($content);
         //}
         $today = date("Y-m-d H:i:s");
         $log = $today . ",fermate sent," . $chat_id . "\n";
         $this->create_keyboard($telegram, $chat_id);
         exit;
     } elseif (strpos($text, '-') !== false) {
         $text = str_replace("-", "", $text);
         $img = curl_file_create('bancadelibro.png', 'image/png');
         $contentp = array('chat_id' => $chat_id, 'photo' => $img);
         $telegram->sendPhoto($contentp);
         sleep(1);
         //  $reply ="Interrogazione del Database di Soldipubblici.gov.it attendere....";
         $reply .= $data->get_libro($text);
         $chunks = str_split($reply, self::MAX_LENGTH);
         foreach ($chunks as $chunk) {
             $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         if ($reply == NULL) {
             $reply .= "\nNessun libro trovato";
             $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         } else {
             $reply = "Se il libro ricercato è in stato DISPONIBILE,\n";
             $reply .= "puoi contattarci tramite il modulo online:\nhttp://goo.gl/forms/RNZpAQplT2";
             $reply .= "\nRicordati di appuntarti il Numero ID !";
             $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         $log = $today . ",libro sent," . $chat_id . "\n";
     } elseif ($text == "/News" || $text == "News") {
         $reply = "Sto interrogano la banca dati per le ultime news dal Comune di Lecce...\n";
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $reply1 = $data->get_news();
         $chunks = str_split($reply1, self::MAX_LENGTH);
         foreach ($chunks as $chunk) {
             // $forcehide=$telegram->buildForceReply(true);
             //chiedo cosa sta accadendo nel luogo
             $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         $log = $today . ",news sent," . $chat_id . "\n";
     } elseif ($text == "/bandi e gare" || $text == "bandi e gare") {
         $reply = "Sto interrogano la banca dati per le ultime news su Bandi e Gare...\n";
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $reply1 = $data->get_bandi();
         $chunks = str_split($reply1, self::MAX_LENGTH);
         foreach ($chunks as $chunk) {
             // $forcehide=$telegram->buildForceReply(true);
             //chiedo cosa sta accadendo nel luogo
             $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         $log = $today . ",bandi e gare sent," . $chat_id . "\n";
     } elseif ($text == "/farmacie aperte ora" || $text == "farmacie aperte ora") {
         $reply = "Sto interrogando la banca dati ...\n";
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         sleep(2);
         $reply1 = $data->get_farmacienow();
         $chunks = str_split($reply1, self::MAX_LENGTH);
         foreach ($chunks as $chunk) {
             $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true, 'parse_mode' => "HTML");
             $telegram->sendMessage($content);
         }
         $log = $today . ",farmacie aperte," . $chat_id . "\n";
     } elseif (strpos($text, 'c:') !== false) {
         $text = str_replace("c:", "", $text);
         $reply = "Sto cercando l'ubicazione per il defunto: " . $text;
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $reply1 = $data->get_oc($text);
         $chunks = str_split($reply1, self::MAX_LENGTH);
         foreach ($chunks as $chunk) {
             $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         $log = $today . ",opencimitero," . $chat_id . "\n";
     } elseif ($text == "/matrimoni" || $text == "matrimoni") {
         $text = str_replace("c:", "", $text);
         $reply = "Luoghi messi a disposizione dal Comune di Lecce per la celebrazione dei matrimoni civili.";
         $reply .= "\nRegolamento: http://goo.gl/xCllG0";
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $reply1 = $data->get_matrimonio($text);
         $chunks = str_split($reply1, self::MAX_LENGTH);
         foreach ($chunks as $chunk) {
             $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         $log = $today . ",matrimoni," . $chat_id . "\n";
     } elseif ($text == "/meteo oggi" || $text == "meteo oggi") {
         $reply = "Previsioni Meteo per oggi:\n" . $data->get_forecast("Lecceoggi");
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         $log = $today . ",previsioni Lecce sent," . $chat_id . "\n";
     } elseif ($text == "/previsioni" || $text == "previsioni") {
         $reply = "Previsioni Meteo :\n" . $data->get_forecast("Lecce");
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         $log = $today . ",previsioni Lecce sent," . $chat_id . "\n";
     } elseif ($text == "/bollettini rischi" || $text == "bollettini rischi") {
         $img = curl_file_create('infoalert.png', 'image/png');
         $contentp = array('chat_id' => $chat_id, 'photo' => $img);
         $telegram->sendPhoto($contentp);
         sleep(1);
         $avviso = "\nInterrogazione in corso al database opendata...";
         $content = array('chat_id' => $chat_id, 'text' => $avviso, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $reply = "Allerta Meteo Protezione Civile Lecce:\n" . $data->get_allertameteo("Lecceoggi");
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         $channel = "@opendatalecce";
         $content = array('chat_id' => "-1001004601038", 'text' => $reply);
         $telegram->sendMessage($content);
         $log = $today . ",rischi sent," . $chat_id . "\n";
     } elseif ($text == "/bot" || $text == "bot") {
         $channel = "@opendatalecce";
         $content = array('chat_id' => "-1001004601038", 'text' => "prova dal bot");
         $telegram->sendMessage($content);
     } elseif ($text == "/hotspot" || $text == "Hot Spot") {
         $avviso = "\nInterrogazione in corso al database opendata...";
         $content = array('chat_id' => $chat_id, 'text' => $avviso, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $reply = $data->get_hotspot("");
         $reply .= "\nPer vedere tutti i luoghi dove è presente un Hot Spot clicca qui:\nhttp://u.osmfr.org/m/61642/";
         //$reply .="\nPer vedere, invece, i luoghi dove è presente un Hot Spot nel raggio di 500mt,\nallora invia la tua posizione cliccando la graffetta \xF0\x9F\x93\x8E e poi digita: hotspot";
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $log = $today . ",hotspot sent," . $chat_id . "\n";
         $img = curl_file_create('hotspot.png', 'image/png');
         $contentp = array('chat_id' => $chat_id, 'photo' => $img);
         $telegram->sendPhoto($contentp);
     } elseif ($text == "/defibrillatori" || $text == "defibrillatori") {
         $img = curl_file_create('dae.png', 'image/png');
         $contentp = array('chat_id' => $chat_id, 'photo' => $img);
         $telegram->sendPhoto($contentp);
         /*
                   $avviso ="\nInterrogazione in corso al database opendata...";
         
                   $content = array('chat_id' => $chat_id, 'text' => $avviso,'disable_web_page_preview'=>true);
                   $telegram->sendMessage($content);
         
                 $reply = $data->get_dae();
               //  $reply ="servizio in manutenzione per i luoghi puntuali.";
                 $reply .="\nPer vedere tutti i luoghi dove è presente un defibrillatore (DAE) clicca qui:\nhttp://u.osmfr.org/m/54531/";
         */
         $reply .= "\nPer vedere i luoghi dove è presente un defribillatore (DAE) nel raggio di 500mt,\ninvia la tua posizione cliccando la graffetta 📎 e poi clicca su /dae";
         $chunks = str_split($reply, self::MAX_LENGTH);
         foreach ($chunks as $chunk) {
             // $forcehide=$telegram->buildForceReply(true);
             //chiedo cosa sta accadendo nel luogo
             $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         //       $content = array('chat_id' => $chat_id, 'text' => $reply,'disable_web_page_preview'=>true);
         //        $telegram->sendMessage($content);
         $log = $today . ",dae sent," . $chat_id . "\n";
     } elseif ($text == "/orari scuole" || $text == "orari scuole") {
         $log = $today . ",temp requested," . $chat_id . "\n";
         $this->create_keyboard_temp_orari($telegram, $chat_id);
         exit;
     } elseif ($text == "/nido comun." || $text == "nido comun.") {
         $reply = $data->get_orariscuole("nido");
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         echo $reply;
         $log = $today . ",orari sent," . $chat_id . "\n";
     } elseif ($text == "/infanzia comunale" || $text == "inf.comun.") {
         $reply = $data->get_orariscuole("infanziacomunale");
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         echo $reply;
         $log = $today . ",orari sent," . $chat_id . "\n";
     } elseif ($text == "/infanzia statale" || $text == "inf.statale") {
         $reply = $data->get_orariscuole("infanziastatale");
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         echo $reply;
         $log = $today . ",orari sent," . $chat_id . "\n";
     } elseif ($text == "/primaria" || $text == "primaria") {
         $reply = $data->get_orariscuole("primaria");
         //  echo $reply;
         $chunks = str_split($reply, self::MAX_LENGTH);
         foreach ($chunks as $chunk) {
             // $forcehide=$telegram->buildForceReply(true);
             //chiedo cosa sta accadendo nel luogo
             $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         //    $content = array('chat_id' => $chat_id, 'text' => $reply);
         //    $telegram->sendMessage($content);
         //  $telegram->forwardMessage($content);
         $log = $today . ",orari sent," . $chat_id . "\n";
     } elseif ($text == "/secondaria primogrado" || $text == "secondaria primogrado") {
         $reply = $data->get_orariscuole("secondaria_primogrado");
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         echo $reply;
         $log = $today . ",orari sent," . $chat_id . "\n";
     } elseif ($text == "/primaria paritaria" || $text == "primaria paritaria") {
         $reply = $data->get_orariscuole("primariaparitaria");
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         echo $reply;
         $log = $today . ",orari sent," . $chat_id . "\n";
     } elseif ($text == "/infanzia paritaria" || $text == "inf.paritaria") {
         $reply = $data->get_orariscuole("infanziaparitaria");
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         echo $reply;
         $log = $today . ",orari sent," . $chat_id . "\n";
     } elseif ($text == "tariffasosta" && $location == null) {
         $reply = "Invia la tua posizione cliccando sulla graffetta 📎 e poi clicca /sosta";
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         $log = $today . ",tariffa_antegps sent," . $chat_id . "\n";
     } elseif ($text == "parcometri" && $location == null) {
         $reply = "Invia la tua posizione cliccando sulla graffetta 📎 e poi clicca /parcometri";
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         $log = $today . ",parcometri_antegps sent," . $chat_id . "\n";
     } elseif ($text == "luoghi accessibili" && $location == null) {
         $reply = "Invia la tua posizione cliccando sulla graffetta 📎 e poi clicca /accessibili";
         $reply .= "\nPuoi contribuire anche tu a censire i luoghi accessibili da disabili in carrozzella";
         $reply .= "\nUsa l'app gratuita Wheelmap oppure direttamente su openstreetmap usa il tag: wheelchair=yes\n";
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         $log = $today . ",accessibili_antegps sent," . $chat_id . "\n";
     } elseif ($text == "stalli parc.disab." && $location == null) {
         $reply = "Invia la tua posizione cliccando sulla graffetta 📎 e poi clicca /stalli";
         $reply .= "\nNota bene: sono indicati tutti gli stalli sosta per disabili, ma alcuni potrebbero essere riservati";
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         $log = $today . ",stalli_antegps sent," . $chat_id . "\n";
     } elseif ($text == "opencimitero") {
         $reply = "opencimitero è un servizio sperimentale di ricerca ubicazione sepoltura defunti\n";
         $reply .= "Digita c:nomedefunto\n";
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
     } elseif ($text == "/aria" || $text == "qualità aria") {
         $avviso = "\nInterrogazione in corso al database opendata...";
         $content = array('chat_id' => $chat_id, 'text' => $avviso, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $reply = $data->get_aria("lecce");
         $reply .= "\nTabella valori di riferimento e info: http://goo.gl/H1nPxO";
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $img = curl_file_create('qaria.png', 'image/png');
         $contentp = array('chat_id' => $chat_id, 'photo' => $img);
         $telegram->sendPhoto($contentp);
         $log = $today . ",aria sent," . $chat_id . "\n";
     } elseif ($text == "/traffico" || $text == "traffico") {
         $reply = $data->get_traffico("lecce");
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $log = $today . ",traffico sent," . $chat_id . "\n";
     } elseif ($text == "/monumenti" || $text == "monumenti") {
         $img = curl_file_create('wikiloves.png', 'image/png');
         $contentp = array('chat_id' => $chat_id, 'photo' => $img);
         $telegram->sendPhoto($contentp);
         sleep(1);
         $avviso = "\nInterrogazione in corso al database opendata...";
         $content = array('chat_id' => $chat_id, 'text' => $avviso, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $reply = "Monumenti che posso essere fotografati e inseriti nel progetto Wikilovesmonuments\n" . $data->get_monumenti("lecce");
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $log = $today . ",monumenti sent," . $chat_id . "\n";
     } elseif ($text == "/mensa scuole" || $text == "mensa scuole") {
         $reply = "Le mense scolastiche riprenderanno ad ottobre";
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $log = $today . ",mense requested," . $chat_id . "\n";
         //  $this->create_keyboard_temp_mensa($telegram,$chat_id);
         //  exit;
     } elseif ($text == "/Infanzia_Aut_Inverno" || $text == "Infanzia_Aut_Inverno" || $text == "mensademo") {
         $avviso = "\nInterrogazione in corso al database opendata...";
         $content = array('chat_id' => $chat_id, 'text' => $avviso, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $giorni = array("Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato");
         $mesi = array("Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre");
         // giorno della settimana in italiano
         $numero_giorno_settimana = date("w");
         $nome_giorno = $giorni[$numero_giorno_settimana];
         if ($nome_giorno == "Sabato" || $nome_giorno == "Domenica") {
             $content = array('chat_id' => $chat_id, 'text' => "Sabato e Domenica non si fornisce il servizio mensa", 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         function datediff($tipo, $partenza, $fine)
         {
             switch ($tipo) {
                 case "A":
                     $tipo = 365;
                     break;
                 case "M":
                     $tipo = 365 / 12;
                     break;
                 case "S":
                     $tipo = 365 / 53;
                     break;
                 case "G":
                     $tipo = 1;
                     break;
             }
             $arr_partenza = explode("/", $partenza);
             $partenza_gg = $arr_partenza[0];
             $partenza_mm = $arr_partenza[1];
             $partenza_aa = $arr_partenza[2];
             $arr_fine = explode("/", $fine);
             $fine_gg = $arr_fine[0];
             $fine_mm = $arr_fine[1];
             $fine_aa = $arr_fine[2];
             $date_diff = mktime(12, 0, 0, $fine_mm, $fine_gg, $fine_aa) - mktime(12, 0, 0, $partenza_mm, $partenza_gg, $partenza_aa);
             $date_diff = floor($date_diff / 60 / 60 / 24 / $tipo);
             return $date_diff;
         }
         $diff = 1;
         $diff1 = -datediff("S", date("d/m/Y"), "05/10/2015");
         if ($diff1 == 10 || $diff1 == 15 || $diff1 == 20 || $diff1 == 25 || $diff1 == 30 || $diff1 == 35 || $diff1 == 40) {
             $diff1 = 5;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         $reply = $data->get_mensa(strtoupper(substr($nome_giorno, 0, 4)), "Infanzia_Aut_Inverno", $diff1);
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $log = $today . ",mensa scolastica sent," . $chat_id . "\n";
     } elseif ($text == "/Primaria_Media_Primavera" || $text == "Primaria_Media_Primavera") {
         $avviso = "\nInterrogazione in corso al database opendata...";
         $content = array('chat_id' => $chat_id, 'text' => $avviso, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $giorni = array("Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato");
         $mesi = array("Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre");
         // giorno della settimana in italiano
         $numero_giorno_settimana = date("w");
         $nome_giorno = $giorni[$numero_giorno_settimana];
         if ($nome_giorno == "Sabato" || $nome_giorno == "Domenica") {
             $content = array('chat_id' => $chat_id, 'text' => "Sabato e Domenica non si fornisce il servizio mensa", 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         function datediff($tipo, $partenza, $fine)
         {
             switch ($tipo) {
                 case "A":
                     $tipo = 365;
                     break;
                 case "M":
                     $tipo = 365 / 12;
                     break;
                 case "S":
                     $tipo = 365 / 53;
                     break;
                 case "G":
                     $tipo = 1;
                     break;
             }
             $arr_partenza = explode("/", $partenza);
             $partenza_gg = $arr_partenza[0];
             $partenza_mm = $arr_partenza[1];
             $partenza_aa = $arr_partenza[2];
             $arr_fine = explode("/", $fine);
             $fine_gg = $arr_fine[0];
             $fine_mm = $arr_fine[1];
             $fine_aa = $arr_fine[2];
             $date_diff = mktime(12, 0, 0, $fine_mm, $fine_gg, $fine_aa) - mktime(12, 0, 0, $partenza_mm, $partenza_gg, $partenza_aa);
             $date_diff = floor($date_diff / 60 / 60 / 24 / $tipo);
             return $date_diff;
         }
         $diff = 1;
         $diff1 = -datediff("S", date("d/m/Y"), "05/10/2015");
         if ($diff1 == 10 || $diff1 == 15 || $diff1 == 20 || $diff1 == 25 || $diff1 == 30 || $diff1 == 35 || $diff1 == 40) {
             $diff1 = 5;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         $reply = $data->get_mensa(strtoupper(substr($nome_giorno, 0, 4)), "Primaria_Media_Primavera", $diff1);
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $log = $today . ",mensa scolastica sent," . $chat_id . "\n";
     } elseif ($text == "/Infanzia_Primavera" || $text == "Infanzia_Primavera") {
         $avviso = "\nInterrogazione in corso al database opendata...";
         $content = array('chat_id' => $chat_id, 'text' => $avviso, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $giorni = array("Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato");
         $mesi = array("Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre");
         // giorno della settimana in italiano
         $numero_giorno_settimana = date("w");
         $nome_giorno = $giorni[$numero_giorno_settimana];
         if ($nome_giorno == "Sabato" || $nome_giorno == "Domenica") {
             $content = array('chat_id' => $chat_id, 'text' => "Sabato e Domenica non si fornisce il servizio mensa", 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         function datediff($tipo, $partenza, $fine)
         {
             switch ($tipo) {
                 case "A":
                     $tipo = 365;
                     break;
                 case "M":
                     $tipo = 365 / 12;
                     break;
                 case "S":
                     $tipo = 365 / 53;
                     break;
                 case "G":
                     $tipo = 1;
                     break;
             }
             $arr_partenza = explode("/", $partenza);
             $partenza_gg = $arr_partenza[0];
             $partenza_mm = $arr_partenza[1];
             $partenza_aa = $arr_partenza[2];
             $arr_fine = explode("/", $fine);
             $fine_gg = $arr_fine[0];
             $fine_mm = $arr_fine[1];
             $fine_aa = $arr_fine[2];
             $date_diff = mktime(12, 0, 0, $fine_mm, $fine_gg, $fine_aa) - mktime(12, 0, 0, $partenza_mm, $partenza_gg, $partenza_aa);
             $date_diff = floor($date_diff / 60 / 60 / 24 / $tipo);
             return $date_diff;
         }
         $diff = 1;
         $diff1 = -datediff("S", date("d/m/Y"), "05/10/2015");
         if ($diff1 == 10 || $diff1 == 15 || $diff1 == 20 || $diff1 == 25 || $diff1 == 30 || $diff1 == 35 || $diff1 == 40) {
             $diff1 = 5;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         $reply = $data->get_mensa(strtoupper(substr($nome_giorno, 0, 4)), "Infanzia_Primavera", $diff1);
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $log = $today . ",mensa scolastica sent," . $chat_id . "\n";
     } elseif ($text == "/Primaria_Media_Aut_Inverno" || $text == "Primaria_Media_Aut_Inverno") {
         $avviso = "\nInterrogazione in corso al database opendata...";
         $content = array('chat_id' => $chat_id, 'text' => $avviso, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $giorni = array("Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato");
         $mesi = array("Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre");
         // giorno della settimana in italiano
         $numero_giorno_settimana = date("w");
         $nome_giorno = $giorni[$numero_giorno_settimana];
         if ($nome_giorno == "Sabato" || $nome_giorno == "Domenica") {
             $content = array('chat_id' => $chat_id, 'text' => "Sabato e Domenica non si fornisce il servizio mensa", 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         function datediff($tipo, $partenza, $fine)
         {
             switch ($tipo) {
                 case "A":
                     $tipo = 365;
                     break;
                 case "M":
                     $tipo = 365 / 12;
                     break;
                 case "S":
                     $tipo = 365 / 53;
                     break;
                 case "G":
                     $tipo = 1;
                     break;
             }
             $arr_partenza = explode("/", $partenza);
             $partenza_gg = $arr_partenza[0];
             $partenza_mm = $arr_partenza[1];
             $partenza_aa = $arr_partenza[2];
             $arr_fine = explode("/", $fine);
             $fine_gg = $arr_fine[0];
             $fine_mm = $arr_fine[1];
             $fine_aa = $arr_fine[2];
             $date_diff = mktime(12, 0, 0, $fine_mm, $fine_gg, $fine_aa) - mktime(12, 0, 0, $partenza_mm, $partenza_gg, $partenza_aa);
             $date_diff = floor($date_diff / 60 / 60 / 24 / $tipo);
             return $date_diff;
         }
         $diff = 1;
         $diff1 = -datediff("S", date("d/m/Y"), "05/10/2015");
         if ($diff1 == 10 || $diff1 == 15 || $diff1 == 20 || $diff1 == 25 || $diff1 == 30 || $diff1 == 35 || $diff1 == 40) {
             $diff1 = 5;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         if ($diff1 - 5 < 5 && $diff1 - 5 > 0) {
             $diff1 = $diff1 - 5;
         } elseif ($diff1 - 5 > 0) {
             $diff1 = $diff1 - 10;
         }
         $reply = $data->get_mensa(strtoupper(substr($nome_giorno, 0, 4)), "Primaria_Media_Aut_Inverno", $diff1);
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $log = $today . ",mensa scolastica sent," . $chat_id . "\n";
     } elseif ($text == "/eventi culturali" || $text == "eventi culturali") {
         $img = curl_file_create('lecce2015.jpg', 'image/jpg');
         $contentp = array('chat_id' => $chat_id, 'photo' => $img);
         $telegram->sendPhoto($contentp);
         sleep(1);
         $avviso = "\nInterrogazione in corso al database opendata...";
         $content = array('chat_id' => $chat_id, 'text' => $avviso, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $reply = "Eventi culturali in programmazione:\n";
         $reply .= $data->get_events();
         //  echo $reply;
         $reply .= "\n\nInfo e testi completi su www.lecce-events.it\n";
         //$reply .=$data->get_traffico("lecce");
         $chunks = str_split($reply, self::MAX_LENGTH);
         foreach ($chunks as $chunk) {
             // $forcehide=$telegram->buildForceReply(true);
             //chiedo cosa sta accadendo nel luogo
             $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true);
             $telegram->sendMessage($content);
         }
         //  $content = array('chat_id' => $chat_id, 'text' => $reply);
         //  $telegram->sendMessage($content);
         $log = $today . ",eventi sent," . $chat_id . "\n";
     } elseif ($text == "/informazioni" || $text == "informazioni") {
         $reply = "openDataLecceBot e' un servizio per il riuso degli openData del Comune di Lecce.\n\nFonti:\nSpese Correnti      -> Soldipubblici.gov.it Lic. CC-BY 3.0\nBollettini rischi   -> Protezione Civile di Lecce - dataset su dati.comune.lecce.it tramite il progetto InfoAlert365 (A cura: Gaetano Lipari)\nEventi culturali    -> Dataset su dati.comune.lecce.it fonte Lecce Events\nQualtà dell'Aria    -> Dataset su dati.comune.lecce.it (A cura: Luciano Mangia)\nL'Acchiappialibri   -> Dataset su dati.comune.lecce.it (A cura: Nuccio Massimiliano)\nDefibrillatori DAE  -> Dataset su dati.comune.lecce.it (A cura: Alessandro Tondi)\nAree sosta          -> Dataset su dati.comune.lecce.it (A cura: Alessandro Tondi)\nStalli parc.disab.  -> Dataset su dati.comune.lecce.it (A cura: Alessandro Tondi)\nParcometri          -> Dataset su dati.comune.lecce.it (A cura: Alessandro Tondi)\nFarmacie            -> Dataset su dati.comune.lecce.it (A cura: Lucio Stefanelli)\nMonumenti           -> Dataset su dati.comune.lecce.it (A cura: Annarita Cairella)\nMensa scolastica    -> Dataset su dati.comune.lecce.it (A cura: Nuccio Massimiliano)\nTrasporti           -> Dataset su dati.comune.lecce.it (A cura: Alessandro Tondi fonte SGM spa)\nLuoghi Matrimoni    -> Dataset su dati.comune.lecce.it (A cura: Gabrilla Muci)\nCont. Pannolini     -> Dataset su dati.comune.lecce.it (A cura: Giuseppe Paladini)\nHot Spot            -> Dataset su dati.comune.lecce.it (A cura: Andrea Lezzi)\nBandi ed esiti gare -> Dataset su dati.comune.lecce.it (A cura: Andrea Lezzi)\nNews                -> Dataset su dati.comune.lecce.it (A cura: Andrea Lezzi)\norari Scuole        -> Dataset su dati.comune.lecce.it (A cura: Nuccio Massimiliano e Elisabetta Indennitate)\nFarmacie aperte     -> Dati su http://www.sanita.puglia.it/gestione-farmacie-di-turno lic. cc-by Regione Puglia\nLuoghi accessibili  -> Dataset su openstreemap Lic. odBL alimentato dalla comunità\nBenzinai            -> Dataset su openstreemap Lic. odBL alimentato dalla comunità\nMusei               -> Dataset su openstreemap Lic. odBL alimentato dalla comunità\nMeteo e temperatura -> Api pubbliche di www.wunderground.com\n\nApplicazione sviluppata da Francesco Piero Paolicelli @piersoft. Codice sorgente per il riuso gratuito: https://goo.gl/bmUNbK\n          ";
         $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         $log = $today . ",crediti sent," . $chat_id . "\n";
     } elseif ($text == "/temperatura" || $text == "temperatura") {
         $log = $today . ",temp requested," . $chat_id . "\n";
         $this->create_keyboard_temp($telegram, $chat_id);
         exit;
     } elseif ($text == "Lecce" || $text == "/temp-lecce") {
         $reply = "Temperatura misurata in zona Lecce centro : " . $data->get_temperature("Lecce centro");
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         $log = $today . ",temperatura Lecce sent," . $chat_id . "\n";
     } elseif ($text == "Nardò" || $text == "/temp-vaianosofignano") {
         $reply = "Temperatura misurata in zona Nardò : " . $data->get_temperature("Nardò");
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         $log = $today . ",temperatura Nardò sent," . $chat_id . "\n";
     } elseif ($text == "Lequile" || $text == "/temp-vaianoschignano") {
         $reply = "Temperatura misurata in zona Lequile : " . $data->get_temperature("Lequile");
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         $log = $today . ",temperatura Lequile sent," . $chat_id . "\n";
     } elseif ($text == "Galatina" || $text == "/temp-montepianovernio") {
         $reply = "Temperatura misurata in zona Galatina : " . $data->get_temperature("Galatina");
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         $log = $today . ",temperatura Galatina sent," . $chat_id . "\n";
     } elseif ($text == "notifiche on" || $text == "/on") {
         //abilita disabilita le notifiche automatiche del servizio
         //memorizza lo user_id
         $statement = "INSERT INTO " . DB_TABLE . " (user_id) VALUES ('" . $user_id . "')";
         $db->exec($statement);
         //		$reply = "Notifiche da openDataLecceBot abilitate. Per disabilitarle digita /off";
         $reply = "Funzione non ancora implementata";
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         $log = $today . ",notification set," . $chat_id . "\n";
     } elseif ($text == "notifiche off" || $text == "/off") {
         //abilita disabilita le notifiche automatiche del servizio
         //memorizza lo user_id
         $statement = "DELETE FROM " . DB_TABLE . " where user_id = '" . $user_id . "'";
         $db->exec($statement);
         //	$reply = "Notifiche da openDataLecceBot disabilitate. Per abilitarle digita /on";
         $reply = "Funzione non ancora implementata";
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         $log = $today . ",notification reset," . $chat_id . "\n";
     } elseif ($text == "l'acchiappalibri" || $text == "/l'acchiappalibri") {
         //  $forcehide=$telegram->buildForceReply(true);
         $img = curl_file_create('bancadelibro.png', 'image/png');
         $contentp = array('chat_id' => $chat_id, 'photo' => $img);
         $telegram->sendPhoto($contentp);
         $content = array('chat_id' => $chat_id, 'text' => "Istituita presso la sede dell’Assessorato alla Pubblica Istruzione in viale Ugo Foscolo 31/a, con la finalità di allargare la comunità dei lettori offre nuovo servizio acquisisce attraverso spontanee liberalità da parte di enti, cittadini, imprenditori, libri per tutte le età, da destinare alle biblioteche scolastiche, alle famiglie in situazioni di disagio e a tutti coloro che in generale amano la lettura. I libri usati ed in ottimo stato di conservazione sono a disposizione di chiunque. Si può quindi ritirare un libro usato e portarne un altro. Giorni e orari del servizio: martedì pomeriggio dalle alle 16.00 alle ore 17.30 mercoledì mattina dalle alle 10.00 alle ore 12.00. Per ricercare un libro, basta anteporre il carattere - (meno) alla parola da cercare; può essere sia una parte del titolo che dell'autore. Esempio -Tamaro piuttosto che -Cuore.\nPer l'elenco completo puoi visitare questo link: http://goo.gl/JBCSAb", 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         exit;
         //----- gestione segnalazioni georiferite : togliere per non gestire le segnalazioni georiferite -----
     } elseif ($text == "trasporti" || $text == "/trasporti") {
         //  $forcehide=$telegram->buildForceReply(true);
         $img = curl_file_create('bus.png', 'image/png');
         $contentp = array('chat_id' => $chat_id, 'photo' => $img);
         $telegram->sendPhoto($contentp);
         $content = array('chat_id' => $chat_id, 'text' => "La partecipata comunale S.G.M.spa ha concesso i dati sui Trasporti Pubblici Locali con licenza e formato aperti. Per vedere i prossimi arrivi di mezzi pubblici in ambito urbano, inviare tramite (📎) la propria posizione e poi cliccare /fermate", 'disable_web_page_preview' => true);
         $telegram->sendMessage($content);
         exit;
         //----- gestione segnalazioni georiferite : togliere per non gestire le segnalazioni georiferite -----
     } elseif ($text == "spese correnti" || $text == "/spese correnti") {
         //  $forcehide=$telegram->buildForceReply(true);
         $content = array('chat_id' => $chat_id, 'text' => "Inserisci la voce di spesa corrente da cercare anteponendo il simbolo ? esempio ?spese postali ", 'reply_to_message_id' => $bot_request_message_id);
         $telegram->sendMessage($content);
         exit;
         //----- gestione segnalazioni georiferite : togliere per non gestire le segnalazioni georiferite -----
     } elseif ($location != null) {
         //  $reply = "Funzione non ancora implementata";
         //    $content = array('chat_id' => $chat_id, 'text' => $reply);
         //    $telegram->sendMessage($content);
         $this->location_manager($db, $telegram, $user_id, $chat_id, $location);
         exit;
     } elseif (strpos($text, '/dae') !== false || strpos($text, '/farmacie') !== false || strpos($text, '/musei') !== false || strpos($text, '/benzine') !== false || strpos($text, '/sosta') !== false || strpos($text, '/parcometri') !== false || strpos($text, '/stalli') !== false || strpos($text, '/accessibili') !== false || strpos($text, '/fermate') !== false || strpos($text, '/pannolini') !== false) {
         $content = array('chat_id' => $chat_id, 'text' => "Attendere prego..");
         // debug
         $telegram->sendMessage($content);
         //inserisce la segnalazione nel DB delle segnalazioni georiferite
         $response = $telegram->getData();
         $type = $response["message"]["video"]["file_id"];
         $text = $response["message"]["text"];
         if (strpos($text, '/') !== false) {
             $text = str_replace("/", "", $text);
         }
         //  if (strpos($text,'/dae') !== false || strpos($text,'/farmacie') !== false ||strpos($text,'/musei') !== false ||strpos($text,'/benzine') !== false ||strpos($text,'/sosta') !== false ||strpos($text,'/parcometri') !== false || strpos($text,'/stalli') !== false || strpos($text,'/accessibili') !== false )
         //  {
         //    $text=str_replace("/","",$text);
         //  }
         $risposta = "";
         $file_name = "";
         $file_path = "";
         $file_name = "";
         if ($type != NULL) {
             $file_id = $type;
             $text = "video allegato";
             $risposta = "ID dell'allegato:" . $file_id;
         }
         $file_id = $response["message"]["photo"][0]["file_id"];
         if ($file_id != NULL) {
             $telegramtk = TELEGRAM_BOT;
             // inserire il token
             $rawData = file_get_contents("https://api.telegram.org/bot" . $telegramtk . "/getFile?file_id=" . $file_id);
             $obj = json_decode($rawData, true);
             $file_path = $obj["result"]["file_path"];
             $caption = $response["message"]["caption"];
             if ($caption != NULL) {
                 $text = $caption;
             }
             $risposta = "ID dell'allegato: " . $file_id;
         }
         $typed = $response["message"]["document"]["file_id"];
         if ($typed != NULL) {
             $file_id = $typed;
             $file_name = $response["message"]["document"]["file_name"];
             $text = "documento: " . $file_name . " allegato";
             $risposta = "ID dell'allegato:" . $file_id;
         }
         $typev = $response["message"]["voice"]["file_id"];
         if ($typev != NULL) {
             $file_id = $typev;
             $text = "audio allegato";
             $risposta = "ID dell'allegato:" . $file_id;
         }
         $csv_path = dirname(__FILE__) . '/./map_data.csv';
         $db_path = dirname(__FILE__) . '/./db/lecceod.sqlite';
         $username = $response["message"]["from"]["username"];
         $first_name = $response["message"]["from"]["first_name"];
         $var = $reply_to_msg['message_id'];
         //  $content = array('chat_id' => $chat_id, 'text' => "id".$var); // debug
         $bot_request_message = $telegram->sendMessage($content);
         $db1 = new SQLite3($db_path);
         $q = "SELECT lat,lng FROM " . DB_TABLE_GEO . " WHERE bot_request_message='" . $var . "'";
         $result = $db1->query($q);
         $row = array();
         $i = 0;
         //  $content = array('chat_id' => $chat_id, 'text' => $row[0]);
         //  $telegram->sendMessage($content);
         while ($res = $result->fetchArray(SQLITE3_ASSOC)) {
             if (!isset($res['lat'])) {
                 continue;
             }
             $row[$i]['lat'] = $res['lat'];
             $row[$i]['lng'] = $res['lng'];
             $i++;
         }
         //inserisce la segnalazione nel DB delle segnalazioni georiferite
         $statement = "UPDATE " . DB_TABLE_GEO . " SET text='" . $text . "',file_id='" . $file_id . "',filename='" . $file_name . "',first_name='" . $first_name . "',file_path='" . $file_path . "',username='******' WHERE bot_request_message ='" . $var . "'";
         print_r($bot_request_message_id);
         $db->exec($statement);
         if ($text === "location" || $text === "benzine" || $text === "farmacie" || $text === "musei" || $text === "fermate" || $text === "sosta" || $text === "defibrillatori1" || $text === "DAE" || $text === "dae" || $text === "Dae" || $text === "dae" || $text == "hotspot" || $text == "Hot Spot" || $text == "hot spot" || $text === "stalli" || $text === "accessibili" || $text === "parcometri" || $text === "pannolini") {
             $around = AROUND;
             $tag = "amenity=pharmacy";
             if ($text === "sosta") {
                 $lon = $row[0]['lng'];
                 $lat = $row[0]['lat'];
                 //   $reply =$data->get_sosta($lat,$lon);
                 $reply .= "\nClicca qui per la risposta: http://dati.comune.lecce.it/bot/sosta/sosta.php?lat=" . $lat . "&lon=" . $lon;
                 $content = array('chat_id' => $chat_id, 'text' => $reply);
                 $telegram->sendMessage($content);
                 $log = $today . ",sosta sent," . $chat_id . "\n";
                 $this->create_keyboard($telegram, $chat_id);
                 exit;
             } elseif ($text === "location") {
                 $lon = $row[0]['lng'];
                 $lat = $row[0]['lat'];
                 //   $reply =$data->get_sosta($lat,$lon);
                 $reply .= "\nlat=" . $lat . " lon=" . $lon;
                 $content = array('chat_id' => $chat_id, 'text' => $reply);
                 $telegram->sendMessage($content);
                 exit;
             } elseif ($text === "musei") {
                 $tag = "tourism=museum";
             } elseif ($text === "pannolini") {
                 $tag = "amenity=recycling";
                 $nome = "Contenitore interrato per conferimento pannolini-pannoloni";
                 $around = 5000;
             } elseif ($text === "benzine") {
                 $tag = "amenity=fuel";
             } elseif ($text === "stalli") {
                 $tag = "capacity:disabled";
                 $nome = "Stallo per disabile";
                 $around = 200;
             } elseif ($text === "accessibili") {
                 $tag = "wheelchair=yes";
                 $around = 200;
             } elseif ($text === "fermate") {
                 $tag = "highway=bus_stop";
                 $around = 500;
                 $lon = $row[0]['lng'];
                 $lat = $row[0]['lat'];
                 $json_string = file_get_contents("https://transit.land/api/v1/stops?lon=" . $lon . "&lat=" . $lat . "&r=" . $around);
                 $parsed_json = json_decode($json_string);
                 $count = 0;
                 $countl = [];
                 $idfermate = [];
                 foreach ($parsed_json->{'stops'} as $data => $csv1) {
                     $count = $count + 1;
                 }
                 $IdFermata = "";
                 //    echo $count;
                 $option = [];
                 //  var_dump($parsed_json->{'stops'}[0]->{'name'});
                 for ($i = 0; $i < $count; $i++) {
                     foreach ($parsed_json->{'stops'}[$i]->{'routes_serving_stop'} as $data => $csv1) {
                         $countl[$i] = $countl[$i] + 1;
                     }
                     //		array_push($option,$parsed_json->{'stops'}[$i]->{'onestop_id'});
                     $option[$i] = $parsed_json->{'stops'}[$i]->{'onestop_id'};
                     $onestop = str_replace("-", "_", $parsed_json->{'stops'}[$i]->{'onestop_id'});
                     $onestop = str_replace("~", "__", $onestop);
                     $onestop = str_replace("<", "___", $onestop);
                     //  echo $countl[$i];
                     $temp_c1 .= "\n";
                     $temp_c1 .= "Fermata: " . $parsed_json->{'stops'}[$i]->{'name'};
                     $temp_c1 .= "\nID Fermata: " . $onestop . "";
                     if ($parsed_json->{'stops'}[$i]->{'tags'}->{'wheelchair_boarding'} != null) {
                         $temp_c1 .= "\nAccesso in carrozzina: " . $parsed_json->{'stops'}[$i]->{'tags'}->{'wheelchair_boarding'};
                     }
                     $temp_c1 .= "\nVisualizzala su:\nhttp://www.openstreetmap.org/?mlat=" . $parsed_json->{'stops'}[$i]->{'geometry'}->{'coordinates'}[1] . "&mlon=" . $parsed_json->{'stops'}[$i]->{'geometry'}->{'coordinates'}[0] . "#map=19/" . $parsed_json->{'stops'}[$i]->{'geometry'}->{'coordinates'}[1] . "/" . $parsed_json->{'stops'}[$i]->{'geometry'}->{'coordinates'}[0];
                     $temp_c1 .= "\n";
                 }
                 $chunks = str_split($temp_c1, self::MAX_LENGTH);
                 foreach ($chunks as $chunk) {
                     // $forcehide=$telegram->buildForceReply(true);
                     //chiedo cosa sta accadendo nel luogo
                     $content = array('chat_id' => $chat_id, 'text' => $chunk, 'reply_to_message_id' => $bot_request_message_id, 'disable_web_page_preview' => true);
                     $telegram->sendMessage($content);
                 }
                 if ($count > 0) {
                     $reply = "Per vedere queste fermate su mappa:\n";
                     $reply .= "http://www.piersoft.it/panarotre/locator.php?lon=" . $lon . "&lat=" . $lat . "&r=500";
                     $content = array('chat_id' => $chat_id, 'text' => $reply, 'reply_markup' => $forcehide, 'disable_web_page_preview' => true);
                     $telegram->sendMessage($content);
                 } else {
                     $content = array('chat_id' => $chat_id, 'text' => "Non ci sono fermate gestite", 'reply_markup' => $forcehide, 'disable_web_page_preview' => true);
                     $telegram->sendMessage($content);
                 }
                 $today = date("Y-m-d H:i:s");
                 $log = $today . ",fermatelocation sent," . $chat_id . "\n";
                 $this->create_keyboard($telegram, $chat_id);
                 $optionf = array([]);
                 for ($i = 0; $i < $count; $i++) {
                     array_push($optionf, ["🚌 /" . $option[$i]]);
                 }
                 $keyb = $telegram->buildKeyBoard($optionf, $onetime = false);
                 $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "[Clicca su 🚌 della fermata]");
                 $telegram->sendMessage($content);
                 exit;
             } elseif ($text === "defibrillatori" || $text === "dae" || $text === "DAE" || $text === "Dae") {
                 $tag = "emergency=defibrillator";
                 $around = 500;
                 //  $suffisso="Puoi visualizzarli su mappa:\nhttp://dati.comune.lecce.it/bot/dae/locator.php?"
             } elseif ($text === "hotspot" || $text === "Hot Spot" || $text == "hot spot") {
                 $tag = "internet_access=wlan";
                 $nome = "Hot Spot Lecce Wireless";
                 $around = 500;
             } elseif ($text === "parcometri") {
                 $tag = "vending=parking_tickets";
                 $around = 200;
             }
             $lon = $row[0]['lng'];
             $lat = $row[0]['lat'];
             //prelevo dati da OSM sulla base della mia posizione
             $osm_data = give_osm_data($lat, $lon, $tag, $around);
             //rispondo inviando i dati di Openstreetmap
             $osm_data_dec = simplexml_load_string($osm_data);
             //per ogni nodo prelevo coordinate e nome
             foreach ($osm_data_dec->node as $osm_element) {
                 $nome = "";
                 $dist = "";
                 $miles = "";
                 $lat10 = "";
                 $long10 = "";
                 $data = "";
                 foreach ($osm_element->tag as $key) {
                     //print_r($key);
                     if ($key['k'] == 'name' || $key['k'] == 'wheelchair' || $key['k'] == 'phone' || $key['k'] == 'addr:street' || $key['k'] == 'bench' || $key['k'] == 'shelter' || $key['k'] == 'wheelchair' || $key['k'] == 'ref') {
                         $valore = utf8_encode($key['v']);
                         $valore = str_replace("yes", "si", $valore);
                         if ($key['k'] == 'wheelchair') {
                             $valore = str_replace("limited", "con limitazioni", $valore);
                             $nome .= "Accessibile in carrozzella: " . $valore;
                         }
                         if ($key['k'] == 'phone') {
                             $nome .= "Telefono: " . utf8_encode($key['v']) . "\n";
                         }
                         if ($key['k'] == 'addr:street') {
                             $nome .= "Indirizzo: " . utf8_encode($key['v']) . "\n";
                         }
                         if ($key['k'] == 'name') {
                             $nome .= "Nome: " . utf8_encode($key['v']) . "\n";
                         }
                         if ($key['k'] == 'bench') {
                             $nome .= "Panchina: " . $valore . "\n";
                         }
                         if ($key['k'] == 'shelter') {
                             $nome .= "Pensilina: " . $valore . "\n";
                         }
                         if ($key['k'] == 'ref') {
                             $nome .= "Parcometro: " . $valore;
                         }
                         if ($text === "pannolini") {
                             $nome = "Contenitore interrato per conferimento pannolini-pannoloni: " . $valore;
                         }
                     }
                 }
                 //gestione musei senza il tag nome
                 if ($nome == "") {
                     if ($text === "hotspot" || $text === "Hot Spot" || $text == "hot spot") {
                         $nome = "Hot Spot Lecce Wireless";
                     }
                     if ($text === "stalli") {
                         $nome = "Stallo per disabile";
                     }
                     //	$nome=utf8_encode("Luogo non presente o identificato su Openstreetmap");
                     //	$content = array('chat_id' => $chat_id, 'text' =>$nome);
                     //	$telegram->sendMessage($content);
                 }
                 $nome = utf8_decode($nome);
                 $content = array('chat_id' => $chat_id, 'text' => $nome);
                 $telegram->sendMessage($content);
                 $longUrl = "http://www.openstreetmap.org/?mlat=" . $osm_element['lat'] . "&mlon=" . $osm_element['lon'] . "#map=19/" . $osm_element['lat'] . "/" . $osm_element['lon'] . "/" . $_POST['qrname'];
                 $apiKey = APIT;
                 //  $apiKey="AIzaSyDe4R1jRRqId46Zl54IPWdCHpF0xotdRIU";
                 $postData = array('longUrl' => $longUrl, 'key' => $apiKey);
                 $jsonData = json_encode($postData);
                 $curlObj = curl_init();
                 curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key=' . $apiKey);
                 curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
                 curl_setopt($curlObj, CURLOPT_HEADER, 0);
                 curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
                 curl_setopt($curlObj, CURLOPT_POST, 1);
                 curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
                 $response = curl_exec($curlObj);
                 // Change the response json string to object
                 $json = json_decode($response);
                 curl_close($curlObj);
                 //  $reply="Puoi visualizzarlo su :\n".$json->id;
                 $shortLink = get_object_vars($json);
                 //return $json->id;
                 $long10 = floatval($osm_element['lon']);
                 $lat10 = floatval($osm_element['lat']);
                 $theta = floatval($lon) - floatval($long10);
                 $dist = floatval(sin(deg2rad($lat)) * sin(deg2rad($lat10)) + cos(deg2rad($lat)) * cos(deg2rad($lat10)) * cos(deg2rad($theta)));
                 $dist = floatval(acos($dist));
                 $dist = floatval(rad2deg($dist));
                 $miles = floatval($dist * 60 * 1.1515 * 1.609344);
                 $data = 0.0;
                 if ($miles >= 1) {
                     $data = number_format($miles, 2, '.', '') . " Km";
                 } else {
                     $data = number_format($miles * 1000, 0, '.', '') . " mt";
                 }
                 $reply = "Puoi visualizzarlo su :\n" . $shortLink['id'] . "\nDista: " . $data . "\n_________";
                 $chunks = str_split($reply, self::MAX_LENGTH);
                 foreach ($chunks as $chunk) {
                     // $forcehide=$telegram->buildForceReply(true);
                     //chiedo cosa sta accadendo nel luogo
                     $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true);
                     $telegram->sendMessage($content);
                 }
                 //		$content = array('chat_id' => $chat_id, 'text' => $reply);
                 //		$telegram->sendMessage($content);
             }
             //if ($text=="farmacie") $around="5km";
             if ($around == 500) {
                 $around = "500 mt";
             } elseif ($around == 200) {
                 $around = "200 mt";
             } else {
                 $around = "5km";
             }
             //crediti dei dati
             if ((bool) $osm_data_dec->node) {
                 $risposta = utf8_encode($text . " attorno alla tua posizione entro " . $around . " \n(dati forniti tramite OpenStreetMap. Licenza ODbL (c) OpenStreetMap contributors)");
                 if ($text == "defibrillatori" || $text == "dae" || $text == "DAE" || $text === "Dae") {
                     //  $content = array('chat_id' => $chat_id, 'text' => $lat." ".$lon);
                     //  $bot_request_message=$telegram->sendMessage($content);
                     $risposta .= "\nPuoi visualizzarli su http://www.piersoft.it/daebot/map/index.php?lat=" . $lat . "&lon=" . $lon . "&r=0.5";
                 }
                 if ($text == "parcometri") {
                     $risposta .= "\nPuoi visualizzarli su http://www.piersoft.it/parcometri/locator.php?lat=" . $osm_element['lat'] . "&lon=" . $osm_element['lon'] . "&r=0.2";
                 }
                 $content = array('chat_id' => $chat_id, 'text' => $risposta);
                 $bot_request_message = $telegram->sendMessage($content);
             } else {
                 $content = array('chat_id' => $chat_id, 'text' => utf8_encode("Non ci sono sono " . $text . " vicini, mi spiace! Se ne conosci uno nelle vicinanze mappalo su www.openstreetmap.org"), 'disable_web_page_preview' => true);
                 $bot_request_message = $telegram->sendMessage($content);
             }
         } else {
             $reply = "La segnalazione è stata Registrata.\n" . $risposta . "\nGrazie! ";
             // creare una mappa su umap, mettere nel layer -> dati remoti -> il link al file map_data.csv
             $longUrl = "http://umap.openstreetmap.fr/it/map/segnalazioni-con-opendataleccebot-x-interni_54105#19/" . $row[0]['lat'] . "/" . $row[0]['lng'] . "/" . $_POST['qrname'];
             $apiKey = APIT;
             //  $apiKey="AIzaSyDe4R1jRRqId46Zl54IPWdCHpF0xotdRIU";
             $postData = array('longUrl' => $longUrl, 'key' => $apiKey);
             $jsonData = json_encode($postData);
             $curlObj = curl_init();
             curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key=' . $apiKey);
             curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
             curl_setopt($curlObj, CURLOPT_HEADER, 0);
             curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
             curl_setopt($curlObj, CURLOPT_POST, 1);
             curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
             $response = curl_exec($curlObj);
             // Change the response json string to object
             $json = json_decode($response);
             curl_close($curlObj);
             //  $reply="Puoi visualizzarlo su :\n".$json->id;
             $shortLink = get_object_vars($json);
             //return $json->id;
             $reply .= "Puoi visualizzarlo su :\n" . $shortLink['id'];
             $content = array('chat_id' => $chat_id, 'text' => $reply);
             $telegram->sendMessage($content);
             $log = $today . ",information for maps recorded," . $chat_id . "\n";
             $csv_path = dirname(__FILE__) . '/./map_data.csv';
             $db_path = dirname(__FILE__) . '/./lecceod.sqlite';
             exec(' sqlite3 -header -csv ' . $db_path . ' "select * from segnalazioni," > ' . $csv_path . ' ');
         }
     } else {
         $reply = "Hai selezionato un comando non previsto";
         $content = array('chat_id' => $chat_id, 'text' => $reply);
         $telegram->sendMessage($content);
         $log = $today . ",wrong command sent," . $chat_id . "\n";
     }
     //gestione messaggi in broadcast : al momento gestisce il database per iscrizione delle notifiche automatiche ma non invia nessuna notifica
     //da commentare per disabilitare la gestione delle notifiche automatiche
     //  	$this->broadcast_manager($db,$telegram);
     //aggiorna tastiera
     $this->create_keyboard($telegram, $chat_id);
     //log
     file_put_contents(dirname(__FILE__) . '/./db/telegram.log', $log, FILE_APPEND | LOCK_EX);
     //db
     //	$statement = "INSERT INTO " . DB_TABLE_LOG ." (date, text, chat_id, user_id, location, reply_to_msg) VALUES ('" . $today . "','" . $text . "','" . $chat_id . "','" . $user_id . "','" . $location . "','" . $reply_to_msg . "')";
     //        $db->exec($statement);
 }
예제 #23
0
if ($rs = $conn->Execute($sSql)) {
    $rs->MoveFirst();
    //繪製日期線條
    $oldlen = 0;
    $all = 0;
    for ($x = 0; $x < $rs->recordcount(); $x++) {
        $dateto = $rs->fields('StudyDate');
        $all_StudyDate = abs(datediff('d', $datefrom, $dateto));
        $all = $all + $all_StudyDate;
        $rs->MoveNext();
    }
    $rs->MoveFirst();
    for ($x = 0; $x < $rs->recordcount(); $x++) {
        $sid = $rs->fields('StudyID');
        $dateto = $rs->fields('StudyDate');
        $all_StudyDate = abs(datediff('d', $datefrom, $dateto));
        $oldlen = $all_StudyDate;
        $oldlen = round($oldlen / $all * 100);
        if ($oldlen <= 1) {
            $oldlen = 5;
        }
        echo "<td width='" . $oldlen . "%' align='left' valign='top' style='background-color:" . $ColorArray[$x] . "' onclick=\"JavaScript:Alert('Hi');\">";
        echo "<font color='#000000'>" . $all_StudyDate . "天前</font> <font color='#0000ff'>" . get_spword($sid) . "</font></td>";
        $rs->MoveNext();
    }
}
?>
	</tr>
</table>
<input type="button" id="refbt" value="包含字詞" onClick="ChangeFunc(1);">        
<input type="hidden" id="pno" value="<?php 
예제 #24
0
	function get_performance($val) {
		$objResponse = new xajaxResponse;
		$kon = new Konek;

		/*
			I : 1 januari - 31 maret
			II : 1 april - 30 juni
			III : 1 juli - 30 september
			IV : 1 oktober - 31 desember
		*/

		switch($val[tw]) {
			case "I" : 
				$tgl_awal = $val[tahun] . "-01-01";
				$tgl_akhir = $val[tahun] . "-03-31";
				$tgl_start_bln = 1;
			break;
			case "II" : 
				$tgl_awal = $val[tahun] . "-04-01";
				$tgl_akhir = $val[tahun] . "-06-30";
				$tgl_start_bln = 4;
			break;
			case "III" : 
				$tgl_awal = $val[tahun] . "-07-01";
				$tgl_akhir = $val[tahun] . "-09-30";
				$tgl_start_bln = 7;
			break;
			case "IV" : 
				$tgl_awal = $val[tahun] . "-10-01";
				$tgl_akhir = $val[tahun] . "-12-31";
				$tgl_start_bln = 10;
			break;
			default :
				// 1 tahun
				$tgl_awal = $val[tahun] . "-01-01";
				$tgl_akhir = $val[tahun] . "-12-31";
				$tgl_start_bln = 1;
			break;
		}
		$selisih_hari = datediff("d", $tgl_awal, $tgl_akhir);

		if($val[kelas]) {
			$qkelas = "AND kmr.kelas = '".$val[kelas]."'";
			$title_kelas = "Kelas " . $val[kelas] . "<br />";
		}
		else $qkelas = "";

		/* 
		get px awal triwulan ~ pasien sisa / pasien yg masih dirawat
		syarat : tgl masuk < tgl_awal 
				 tgl_keluar > tgl_awal
		*/
		$kon->sql = "
			SELECT 
				COUNT(kk.id) as jml
			FROM
				kunjungan_kamar kk
				JOIN kamar kmr ON (kmr.id = kk.kamar_id)
				JOIN kunjungan k ON (k.id = kk.kunjungan_id)
				JOIN pelayanan pel ON (kmr.pelayanan_id = pel.id)
			WHERE
				pel.jenis = 'RAWAT INAP'
				AND (DATE(kk.tgl_daftar) < '".$tgl_awal."' AND (DATE(kk.tgl_keluar) >= '".$tgl_awal."' OR kk.tgl_keluar IS NULL))
				$qkelas
		";
		$kon->execute();
		$px_awal = $kon->getOne();
		$total[px_awal] += $px_awal[jml];

		/* 
		get px masuk
		ASUMSI SEMENTARA : PASIEN PINDAHAN DIHITUNG
		syarat : tgl masuk diantara tgl_awal dan tgl_keluar
		*/
		$kon->sql = "
			SELECT 
				COUNT(kk.id) as jml
			FROM
				kunjungan_kamar kk
				JOIN kamar kmr ON (kmr.id = kk.kamar_id)
				JOIN kunjungan k ON (k.id = kk.kunjungan_id)
				JOIN pelayanan pel ON (kmr.pelayanan_id = pel.id)
			WHERE
				pel.jenis = 'RAWAT INAP'
				AND (DATE(kk.tgl_daftar) BETWEEN '".$tgl_awal."' AND '".$tgl_akhir."')
				$qkelas
		";
		$kon->execute();
		$px_masuk = $kon->getOne();
		$total[px_masuk] += $px_masuk[jml];

		/* 
		get px keluar 
		syarat : tgl keluar diantara tgl_awal dan tgl_keluar dan keadaan keluar = sembuh, belum sembuh
		*/
		$kon->sql = "
			SELECT 
				COUNT(kk.id) as jml,
				k.keadaan_keluar as keadaan_keluar
			FROM
				kunjungan_kamar kk
				JOIN kamar kmr ON (kmr.id = kk.kamar_id)
				JOIN kunjungan k ON (k.id = kk.kunjungan_id)
				JOIN pelayanan pel ON (kmr.pelayanan_id = pel.id)
			WHERE
				pel.jenis = 'RAWAT INAP'
				AND (DATE(kk.tgl_keluar) BETWEEN '".$tgl_awal."' AND '".$tgl_akhir."')
				$qkelas
			GROUP BY kk.id
		";
		$kon->execute();
		$px_keluar = $kon->getAll();
		for($j=0;$j<sizeof($px_keluar);$j++) {
			switch($px_keluar[$j][keadaan_keluar]) {
				case "MATI < 48 JAM" :
					$total[px_keluar_mati_kurang_dari] += $px_keluar[$j][jml];
					$total[px_keluar_mati] += $px_keluar[$j][jml];
				break;
				case "MATI >= 48 JAM" :
					$total[px_keluar_mati_lebih_dari] += $px_keluar[$j][jml];
					$total[px_keluar_mati] += $px_keluar[$j][jml];
				break;
				default :
					$total[px_keluar_hidup] += $px_keluar[$j][jml];
				break;
			}
		}
		$total[px_keluar] = $total[px_keluar_mati] + $total[px_keluar_hidup];

		/* 
		get jumlah lama dirawat ~ lamanya seorang pasien dirawat
		syarat : tgl keluar diantara tgl_awal dan tgl_keluar 
				 hitung tgl_keluar-tanggal_daftar
				 
		cara : cari dulu px yg keluar pada tw tsb
			   hitung tgl_keluar-tanggal_daftar
			   jika tgl_keluar = tgl_daftar -> dihitung 1 hari lama dirawat
		*/
		$kon->sql = "
			SELECT 
				kk.id as kkid,
				CASE
					WHEN (DATE(kk.tgl_daftar) = DATE(kk.tgl_keluar)) THEN 1
					ELSE DATEDIFF(kk.tgl_keluar, kk.tgl_daftar)
				END as jml
			FROM
				kunjungan_kamar kk
				JOIN kamar kmr ON (kmr.id = kk.kamar_id)
				JOIN pelayanan pel ON (kmr.pelayanan_id = pel.id)
			WHERE
				pel.jenis = 'RAWAT INAP'
				AND (DATE(kk.tgl_keluar) BETWEEN '".$tgl_awal."' AND '".$tgl_akhir."')
				$qkelas
			GROUP BY kk.id
		";
		$kon->execute();
		$ld = $kon->getAll();
		for($j=0;$j<sizeof($ld);$j++) {
			$total[lama_dirawat] += $ld[$j][jml];
		}

		/* 
		get px akhir triwulan ~ pasien sisa / pasien yg masih dirawat
		syarat : tgl masuk < tgl_akhir 
				 tgl_keluar > tgl_akhir
		*/
		$kon->sql = "
			SELECT 
				COUNT(kk.id) as jml
			FROM
				kunjungan_kamar kk
				JOIN kamar kmr ON (kmr.id = kk.kamar_id)
				JOIN kunjungan k ON (k.id = kk.kunjungan_id)
				JOIN pelayanan pel ON (kmr.pelayanan_id = pel.id)
			WHERE
				pel.jenis = 'RAWAT INAP'
				AND (DATE(kk.tgl_daftar) < '".$tgl_akhir."' AND (DATE(kk.tgl_keluar) > '".$tgl_akhir."' OR kk.tgl_keluar IS NULL))
				$qkelas
		";
		$kon->execute();
		$px_akhir = $kon->getOne();
		$total[px_akhir] += $px_akhir[jml];

		/* 
		get jumlah hari perawatan ~ pasien sisa per hari
		sampe sini
		*/
		//sampe sini 7/4/2007 
		for($j=0;$j<=$selisih_hari;$j++) {
			$tgl = @date("Y-m-d", @mktime(1, 1, 1, $tgl_start_bln, ($j+1), $val[tahun]));
			$kon->sql = "
				SELECT 
					COUNT(kk.id) as jml,
					kmr.kelas as kelas
				FROM
					kunjungan_kamar kk
					JOIN kamar kmr ON (kmr.id = kk.kamar_id)
					JOIN kunjungan k ON (k.id = kk.kunjungan_id)
					JOIN pelayanan pel ON (kmr.pelayanan_id = pel.id)
				WHERE
					pel.jenis = 'RAWAT INAP'
					AND (DATE(kk.tgl_daftar) <= '".$tgl."' AND (DATE(kk.tgl_keluar) > '".$tgl."' OR kk.tgl_keluar IS NULL))
					$qkelas
				GROUP BY kmr.kelas
			";
			$kon->execute();
			$px_hari_ini[$j] = $kon->getAll();
			for($k=0;$k<sizeof($px_hari_ini[$j]);$k++) {
				$total[hp_total] += $px_hari_ini[$j][$k][jml];
			}
		}

		$kon->sql = "SELECT SUM(kmr.jml_bed) as jml FROM kamar kmr WHERE 1=1 " . $qkelas;
		$kon->execute();
		$tt = $kon->getOne();
//
		/*
		BOR = (jml hari perawatan / jml TT * jml hari) * 100%;
		AvLOS = (jml lama dirawat / jml px keluar)
		BTO = jml px keluar / jml TT
		TOI = (jml TT * periode - jml HP)/ jml px keluar
		GDR = (jml px mati/ jml px keluar) x 1000 permil
		NDR = (jml px mati > 48 jam/ jml px keluar) x 1000 permil
		RATA2 kunjungan poliklinik
		*/
		$per = array();
		unset($_SESSION[rekmed][performance]);
		$selisih_hari = $selisih_hari + 1;
		$per[bor] = @round(($total[hp_total]*100) / ($tt[jml] * $selisih_hari), 2);
		$per[avlos] = @round($total[lama_dirawat] / $total[px_keluar]);
		$per[bto] = @round($total[px_keluar] / $tt[jml], 2);
		$per[toi] = @round(($tt[jml] * $selisih_hari - $total[hp_total]) / $total[px_keluar]);
		$per[gdr] = @round(($total[px_keluar_mati] * 1000) / $total[px_keluar], 2);
		$per[ndr] = @round(($total[px_keluar_mati_lebih_dari] * 1000) / $total[px_keluar], 2);
		$title = "Performance Rumah Sakit<br />".$title_kelas."Periode Triwulan " . $val[tw] . " Tahun " . $val[tahun];
		$objResponse->addAssign("performance_title", "innerHTML", $title);
		$_SESSION[rekmed][performance][graph] = "<img src=\"" . URL . "rekmed/barber_johnson/?md5=".md5(date("Ymdhis"))."\" alt=\"Barber Johnson\" />";
		$_SESSION[rekmed][performance][graph_resize] = "<img src=\"" . URL . "rekmed/barber_johnson/?md5=".md5(date("Ymdhis"))."\" alt=\"Barber Johnson\" height=\"600\"/>";
		$_SESSION[rekmed][performance][per] = $per;
		$objResponse->addAssign("graph", "innerHTML", $_SESSION[rekmed][performance][graph]);

		$table = new Table;
		$table->scroll = false;
		$table->addTh("Indikator", "Nilai", "Nilai Standar");
		$table->addRow("BOR", $per[bor] . " %", "60 - 85 %");
		$table->addRow("AvLOS", $per[avlos] . " hari", "6 - 9 hari");
		$table->addRow("BTO", $per[bto] . " kali per triwulan", "40 - 50 kali per tahun");
		$table->addRow("TOI", $per[toi] . " hari", "1 - 3 hari");
		$table->addRow("GDR", $per[gdr] . " &permil;", "45 &permil;");
		$table->addRow("NDR", $per[ndr] . " &permil;", "25 &permil;");
		$_SESSION[rekmed][performance][bj] = $per;
		$_SESSION[rekmed][performance][bj][selisih_hari] = $selisih_hari;
		$_SESSION[rekmed][performance][selisih_hari] = $selisih_hari;
		$_SESSION[rekmed][performance][title] = $title;
		$_SESSION[rekmed][performance][th_0] = $table->Th[0];
		$_SESSION[rekmed][performance][row] = $table->Row;
		$ret = $table->build();
		$objResponse->addAssign("performance_list_data", "innerHTML", $ret);

		$objResponse->addAssign("performance_param_title", "innerHTML", "Parameter Performance Rumah Sakit<br />".$title_kelas."Periode Triwulan " . $val[tw] . " Tahun " . $val[tahun]);
		$table_param = new Table;
		$table_param->scroll = false;
		$table_param->addTh("Parameter", "Nilai");
		$table_param->addRow("Total Lama Dirawat", $total[lama_dirawat]);
		$table_param->addRow("Total Hari Perawatan", $total[hp_total]);
		$table_param->addRow("Pasien Keluar Mati Lebih Dari", $total[px_keluar_mati_lebih_dari]);
		$table_param->addRow("Pasien Keluar", $total[px_keluar]);
		$table_param->addRow("Jumlah TT", $tt[jml]);
		$table_param->addRow("Jumlah Hari", $selisih_hari);
		$ret2 = $table_param->build();
		$objResponse->addAssign("performance_param_list_data", "innerHTML", $ret2);

//
		return $objResponse;
	}
예제 #25
0
파일: lap_rl1.php 프로젝트: reekoheek/srmis
	function get_lap_rl1($val) {
		$objResponse = new xajaxResponse;
		$kon = new Konek;
		$sql = "
			SELECT
				id,
				nama as nama_lain
			FROM
				pelayanan
			WHERE
				jenis = 'RAWAT INAP'
		";
		$kon->sql = $sql;
		$kon->execute();
		$data = $kon->getAll();
		$baru = array();
		$s = 0;
		
		/*
			I : 1 januari - 31 maret
			II : 1 april - 30 juni
			III : 1 juli - 30 september
			IV : 1 oktober - 31 desember
		*/

		switch($val[tw]) {
			case "I" : 
				$tgl_awal = $val[tahun] . "-01-01";
				$tgl_akhir = $val[tahun] . "-03-31";
				$tgl_start_bln = 1;
			break;
			case "II" : 
				$tgl_awal = $val[tahun] . "-04-01";
				$tgl_akhir = $val[tahun] . "-06-30";
				$tgl_start_bln = 4;
			break;
			case "III" : 
				$tgl_awal = $val[tahun] . "-07-01";
				$tgl_akhir = $val[tahun] . "-09-30";
				$tgl_start_bln = 7;
			break;
			default : 
				$tgl_awal = $val[tahun] . "-10-01";
				$tgl_akhir = $val[tahun] . "-12-31";
				$tgl_start_bln = 10;
			break;
		}
		$selisih_hari = datediff("d", $tgl_awal, $tgl_akhir);
		for($i=0;$i<sizeof($data);$i++) {
			$baru[$i][nama] = $data[$i][nama_lain];
			/* 
			get px awal triwulan ~ pasien sisa / pasien yg masih dirawat
			syarat : tgl masuk < tgl_awal 
					 tgl_keluar > tgl_awal
			*/
			$kon->sql = "
				SELECT 
					COUNT(kk.id) as jml
				FROM
					kunjungan_kamar kk
					JOIN kamar kmr ON (kmr.id = kk.kamar_id)
					JOIN kunjungan k ON (k.id = kk.kunjungan_id)
				WHERE
					kmr.pelayanan_id = '".$data[$i][id]."'
					AND (DATE(kk.tgl_daftar) < '".$tgl_awal."' AND (DATE(kk.tgl_keluar) >= '".$tgl_awal."' OR kk.tgl_keluar IS NULL))
			";
			$kon->execute();
			$px_awal = $kon->getOne();
			$baru[$i][px_awal] = $px_awal[jml];
			$total[px_awal] += $baru[$i][px_awal];

			/* 
			get px masuk
			ASUMSI SEMENTARA : PASIEN PINDAHAN DIHITUNG
			syarat : tgl masuk diantara tgl_awal dan tgl_keluar
			*/
			$kon->sql = "
				SELECT 
					COUNT(kk.id) as jml
				FROM
					kunjungan_kamar kk
					JOIN kamar kmr ON (kmr.id = kk.kamar_id)
					JOIN kunjungan k ON (k.id = kk.kunjungan_id)
				WHERE
					kmr.pelayanan_id = '".$data[$i][id]."'
					AND (DATE(kk.tgl_daftar) BETWEEN '".$tgl_awal."' AND '".$tgl_akhir."')
			";
			$kon->execute();
			$px_masuk = $kon->getOne();
			$baru[$i][px_masuk] = $px_masuk[jml];
			$total[px_masuk] += $baru[$i][px_masuk];

			/* 
			get px keluar 
			syarat : tgl keluar diantara tgl_awal dan tgl_keluar dan keadaan keluar = sembuh, belum sembuh
			*/
			$kon->sql = "
				SELECT 
					COUNT(kk.id) as jml,
					k.keadaan_keluar as keadaan_keluar
				FROM
					kunjungan_kamar kk
					JOIN kamar kmr ON (kmr.id = kk.kamar_id)
					JOIN kunjungan k ON (k.id = kk.kunjungan_id)
				WHERE
					kmr.pelayanan_id = '".$data[$i][id]."'
					AND (DATE(kk.tgl_keluar) BETWEEN '".$tgl_awal."' AND '".$tgl_akhir."')
				GROUP BY kk.id
			";
			$kon->execute();
			$px_keluar = $kon->getAll();
			for($j=0;$j<sizeof($px_keluar);$j++) {
				switch($px_keluar[$j][keadaan_keluar]) {
					case "MATI < 48 JAM" :
						$baru[$i][px_keluar_mati_kurang_dari] += $px_keluar[$j][jml];
					break;
					case "MATI >= 48 JAM" :
						$baru[$i][px_keluar_mati_lebih_dari] += $px_keluar[$j][jml];
					break;
					default :
						$baru[$i][px_keluar_hidup] += $px_keluar[$j][jml];
					break;
				}
			}
			$total[px_keluar_mati_kurang_dari] += $baru[$i][px_keluar_mati_kurang_dari];
			$total[px_keluar_mati_lebih_dari] += $baru[$i][px_keluar_mati_lebih_dari];
			$total[px_keluar_hidup] += $baru[$i][px_keluar_hidup];
			$baru[$i][px_keluar_mati] = $baru[$i][px_keluar_mati_kurang_dari] + $baru[$i][px_keluar_mati_lebih_dari];
			$total[px_keluar_mati] += $baru[$i][px_keluar_mati];

			/* 
			get jumlah lama dirawat ~ lamanya seorang pasien dirawat
			syarat : tgl keluar diantara tgl_awal dan tgl_keluar 
					 hitung tgl_keluar-tanggal_daftar
					 
			cara : cari dulu px yg keluar pada tw tsb
				   hitung tgl_keluar-tanggal_daftar
				   jika tgl_keluar = tgl_daftar -> dihitung 1 hari lama dirawat
			*/
			$kon->sql = "
				SELECT 
					kk.id as kkid,
					CASE
						WHEN (DATE(kk.tgl_daftar) = DATE(kk.tgl_keluar)) THEN 1
						ELSE DATEDIFF(kk.tgl_keluar, kk.tgl_daftar)
					END as jml
				FROM
					kunjungan_kamar kk
					JOIN kamar kmr ON (kmr.id = kk.kamar_id)
				WHERE
					kmr.pelayanan_id = '".$data[$i][id]."'
					AND (DATE(kk.tgl_keluar) BETWEEN '".$tgl_awal."' AND '".$tgl_akhir."')
				GROUP BY kk.id
			";
			$kon->execute();
			$ld = $kon->getAll();
			for($j=0;$j<sizeof($ld);$j++) {
				$baru[$i][lama_dirawat] += $ld[$j][jml];
			}
			$total[lama_dirawat] += $baru[$i][lama_dirawat];

			/* 
			get px akhir triwulan ~ pasien sisa / pasien yg masih dirawat
			syarat : tgl masuk < tgl_akhir 
					 tgl_keluar > tgl_akhir
			*/
			$kon->sql = "
				SELECT 
					COUNT(kk.id) as jml
				FROM
					kunjungan_kamar kk
					JOIN kamar kmr ON (kmr.id = kk.kamar_id)
					JOIN kunjungan k ON (k.id = kk.kunjungan_id)
				WHERE
					kmr.pelayanan_id = '".$data[$i][id]."'
					AND (DATE(kk.tgl_daftar) < '".$tgl_akhir."' AND (DATE(kk.tgl_keluar) > '".$tgl_akhir."' OR kk.tgl_keluar IS NULL))
			";
			$kon->execute();
			$px_akhir = $kon->getOne();
			$baru[$i][px_akhir] = $px_akhir[jml];
			$total[px_akhir] += $baru[$i][px_akhir];

			/* 
			get jumlah hari perawatan ~ pasien sisa per hari
			sampe sini
			*/
			//sampe sini 7/4/2007 
			for($j=0;$j<=$selisih_hari;$j++) {
				$tgl = @date("Y-m-d", @mktime(1, 1, 1, $tgl_start_bln, ($j+1), $val[tahun]));
				$kon->sql = "
					SELECT 
						COUNT(kk.id) as jml,
						kmr.kelas as kelas
					FROM
						kunjungan_kamar kk
						JOIN kamar kmr ON (kmr.id = kk.kamar_id)
						JOIN kunjungan k ON (k.id = kk.kunjungan_id)
					WHERE
						kmr.pelayanan_id = '".$data[$i][id]."'
						AND (DATE(kk.tgl_daftar) <= '".$tgl."' AND (DATE(kk.tgl_keluar) > '".$tgl."' OR kk.tgl_keluar IS NULL))
					GROUP BY kmr.kelas
				";
				$kon->execute();
				$px_hari_ini[$j] = $kon->getAll();
				for($k=0;$k<sizeof($px_hari_ini[$j]);$k++) {
					switch($px_hari_ini[$j][$k][kelas]) {
						case "I" :
							$baru[$i][hp_kelas_i] += $px_hari_ini[$j][$k][jml];
						break;
						case "II" :
							$baru[$i][hp_kelas_ii] += $px_hari_ini[$j][$k][jml];
						break;
						case "III" :
							$baru[$i][hp_kelas_iii] += $px_hari_ini[$j][$k][jml];
						break;
						case "VIP" :
							$baru[$i][hp_kelas_vip] += $px_hari_ini[$j][$k][jml];
						break;
						default :
							$baru[$i][hp_kelas_tanpa_kelas] += $px_hari_ini[$j][$k][jml];
						break;
					}
				}
			}
			$total[hp_kelas_i] += $baru[$i][hp_kelas_i];
			$total[hp_kelas_ii] += $baru[$i][hp_kelas_ii];
			$total[hp_kelas_iii] += $baru[$i][hp_kelas_iii];
			$total[hp_kelas_vip] += $baru[$i][hp_kelas_vip];
			$total[hp_kelas_tanpa_kelas] += $baru[$i][hp_kelas_tanpa_kelas];
			$baru[$i][hp_total] +=$baru[$i][hp_kelas_i] + $baru[$i][hp_kelas_ii] + $baru[$i][hp_kelas_iii] + $baru[$i][hp_kelas_vip] + $baru[$i][hp_kelas_tanpa_kelas];
			$total[hp_total] += $baru[$i][hp_total];
		}
		$tabel_all = new Table;
		$tabel_all->scroll = false;
		$tabel_all->extra_table = "style=\"width:27cm;margin:0\"";
		$tabel_all->cellspacing="0";
		$tabel_all->css_table="";
		$tabel_all->anime_bg_color="";
		$tabel_header = new Table;
		$tabel_header->scroll = false;
		$tabel_header->extra_tr_th = "";
		$tabel_header->cellspacing="0";
		$tabel_header->css_table="";
		$tabel_header->anime_bg_color="";
		$tabel_header->extra_table = "style=\"width:27cm;border:0;\"";
		$tabel_header->addTh("","DATA KEGIATAN RUMAH SAKIT<br />TRIWULAN : ".$val[tw]."<br />TAHUN : ".$val[tahun]."");
		//$tabel_header->addExtraTh("colspan=\"3\"");
		$tabel_header->addRow("","","Formulir RL1");
		//$tabel_header->addExtraTh();
		$tabel_header->addRow($_SESSION[setting][rs_nama], "", "No. Kode RS : " . $_SESSION[setting][rs_kode]);
		//$tabel_header->addExtraTh("colspan=\"3\"");

		$tabel_isi = new Table;
		$tabel_isi->scroll = false;
		$tabel_isi->cellspacing="0";
		$tabel_isi->extra_table = "style=\"width:27cm;font-size:7pt;\"";
		$tabel_header->css_table="";
		$tabel_isi->addTh(
			"No.", 
			"JENIS PELAYANAN", 
			"Pasien<br />Awal<br />Triwulan", 
			"Pasien<br />Masuk", 
			"Pasien<br />Keluar<br />Hidup", 
			"Pasien Keluar Mati", 
			"Jumlah<br />Lama<br />Dirawat", 
			"Pasien<br />Akhir<br />Triwulan",
			"Jumlah<br />Hari Pe-<br />rawatan",
			"Rincian Hari Perawatan per Kelas",
			"No."
		);
		$tabel_isi->addExtraTh(
			"rowspan=\"2\"", 
			"rowspan=\"2\"", 
			"rowspan=\"2\"", 
			"rowspan=\"2\"", 
			"rowspan=\"2\"", 
			"colspan=\"3\"", 
			"rowspan=\"2\"", 
			"rowspan=\"2\"",
			"rowspan=\"2\"", 
			"colspan=\"5\"", 
			"rowspan=\"2\""
		);
		$tabel_isi->addTh("&lt; 48 jam", "&ge; 48 jam", "jumlah", "Kelas<br />Utama", "Kelas I", "Kelas II", "Kelas III", "Tanpa<br />Kelas");
		$tabel_isi->addTh("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17");
		for($i=0;$i<sizeof($baru);$i++) {
			$tabel_isi->addRow(
				($i+1),
				$baru[$i][nama],
				$baru[$i][px_awal],
				$baru[$i][px_masuk],
				$baru[$i][px_keluar_hidup],
				$baru[$i][px_keluar_mati_kurang_dari],
				$baru[$i][px_keluar_mati_lebih_dari],
				$baru[$i][px_keluar_mati],
				$baru[$i][lama_dirawat],
				$baru[$i][px_akhir],
				$baru[$i][hp_total],
				$baru[$i][hp_kelas_vip],
				$baru[$i][hp_kelas_i],
				$baru[$i][hp_kelas_ii],
				$baru[$i][hp_kelas_iii],
				$baru[$i][hp_kelas_tanpa_kelas],
				($i+1)
			);
		}
		$tabel_isi->addRow(
			99,
			"TOTAL",
			$total[px_awal],
			$total[px_masuk],
			$total[px_keluar_hidup],
			$total[px_keluar_mati_kurang_dari],
			$total[px_keluar_mati_lebih_dari],
			$total[px_keluar_mati],
			$total[lama_dirawat],
			$total[px_akhir],
			$total[hp_total],
			$total[hp_kelas_vip],
			$total[hp_kelas_i],
			$total[hp_kelas_ii],
			$total[hp_kelas_iii],
			$total[hp_kelas_tanpa_kelas],
			99
		);
		$ret_tabel_header = $tabel_header->build();
		$ret_tabel_isi = $tabel_isi->build();
		$tabel_all->addRow($ret_tabel_header);
		$tabel_all->addRow($ret_tabel_isi);
		$ret = $tabel_all->build();
		unset($_SESSION[rekmed][lap_rl1]);
		$cetak = new Cetak;
		$tanda_tangan = $cetak->setTandaTangan();
		$ret .= $tanda_tangan;
		$_SESSION[rekmed][lap_rl1] = $ret;
		$objResponse->addAssign("list_data", "innerHTML", $ret);
		return $objResponse;
	}
예제 #26
0
	function get_kunjungan($val) {
		unset($_SESSION[igd][statistik_kunjungan_igd]);
		$tgl_start = @date("Y-m-d", @mktime(1,1,1,$val[tgl_periksa_bln_start], $val[tgl_periksa_tgl_start], $val[tgl_periksa_thn_start]));
		$tgl_end = @date("Y-m-d", @mktime(1,1,1,$val[tgl_periksa_bln_end], $val[tgl_periksa_tgl_end], $val[tgl_periksa_thn_end]));
		$title = "Statistik Kunjungan IRD";
		
		if($val[tampilkan] == "hari") {
			$selisih = datediff('d', $tgl_start, $tgl_end);
		} elseif($val[tampilkan] == "bulan") {
			$selisih = datediff('m', $tgl_start, $tgl_end);
		} else {
			$selisih = datediff('y', $tgl_start, $tgl_end);
		}
		if($val[tampilkan] == "hari") {
			$tanggal_awal = tanggalIndo($tgl_start, "j F Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "j F Y");
		} elseif($val[tampilkan] == "bulan") {
			$tanggal_awal = tanggalIndo($tgl_start, "F Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "F Y");
		} else {
			$tanggal_awal = tanggalIndo($tgl_start, "Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "Y");
		}

		$title .= "\nPeriode " . $tanggal_awal . " s.d. " . $tanggal_akhir;

		$arr_tgl_start = explode("-",$tgl_start);
		$tgl_start_tgl = $arr_tgl_start[2];
		$tgl_start_bln = $arr_tgl_start[1];
		$tgl_start_thn = $arr_tgl_start[0];

		$arr_tgl_end = explode("-",$tgl_end);
		$tgl_end_tgl = $arr_tgl_end[2];
		$tgl_end_bln = $arr_tgl_end[1];
		$tgl_end_thn = $arr_tgl_end[0];

		$objResponse = new xajaxResponse();
		$kon = new Konek;
		$kon->sql = "SELECT id, nama, hari_buka FROM pelayanan WHERE jenis = 'RAWAT JALAN'";
		$kon->execute();
		$poli = $kon->getAll();
		
		for($i=0;$i<=$selisih;$i++) {
			if($val[tampilkan] == "hari") {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, $tgl_start_bln, ($i+$tgl_start_tgl), $tgl_start_thn));
				$tgl_periksa[$i] = tanggalIndo($tgl[$i], "j M\nY");
				$_SESSION[igd][statistik_kunjungan_igd][label_tick][$i] = @date("j", @mktime(1, 1, 1,$tgl_start_bln, ($tgl_start_tgl+$i), $tgl_start_thn));
				$label_x[$i] = @date("M Y", @mktime(1, 1, 1, $tgl_start_bln, ($tgl_start_tgl+$i), $tgl_start_thn));
				$where = " AND DATE(kk.tgl_periksa) = '" . $tgl[$i] . "' ";
			} elseif($val[tampilkan] == "bulan") {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$tgl_periksa[$i] = tanggalIndo($tgl[$i], "M\nY");
				$_SESSION[igd][statistik_kunjungan_igd][label_tick][$i] = @date("M y", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$label_x[$i] = @date("Y", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$where = " AND EXTRACT(YEAR_MONTH FROM kk.tgl_periksa) = EXTRACT(YEAR_MONTH FROM '" . $tgl[$i] . "') ";
			} else {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, 1, 1, ($tgl_start_thn + $i)));
				$tgl_periksa[$i] = tanggalIndo($tgl[$i], "Y");
				$_SESSION[igd][statistik_kunjungan_igd][label_tick][$i] = @date("Y", @mktime(1, 1, 1, 1, 1, ($tgl_start_thn+$i)));
				$label_x[$i] = "Tahun";
				$where = " AND YEAR(kk.tgl_periksa) = YEAR('" . $tgl[$i] . "') ";
			}
			
			$sql = "
				SELECT
					COUNT(kk.id) as jml_baru
				FROM
					kunjungan_kamar kk 
					JOIN kunjungan k ON (k.id = kk.kunjungan_id)
					JOIN pasien p ON (p.id = k.pasien_id)
					JOIN kamar kmr ON (kmr.id = kk.kamar_id)
					JOIN pelayanan pel ON (pel.id = kmr.pelayanan_id)
				WHERE
					DATE(kk.tgl_periksa) = DATE(p.tgl_daftar)
					AND pel.jenis = 'IGD'
					$where
				GROUP BY
					pel.id
				";
			$kon->sql = $sql;
			$kon->execute();
			$baru[$i] = $kon->getOne();
			if(!$baru[$i][jml_baru]) $baru[$i][jml_baru] = 0;

			$sql = "
				SELECT
					COUNT(kk.id) as jml_lama
				FROM
					kunjungan_kamar kk 
					JOIN kunjungan k ON (k.id = kk.kunjungan_id)
					JOIN pasien p ON (p.id = k.pasien_id)
					JOIN kamar kmr ON (kmr.id = kk.kamar_id)
					JOIN pelayanan pel ON (pel.id = kmr.pelayanan_id)
				WHERE
					DATE(kk.tgl_periksa) <> DATE(p.tgl_daftar)
					AND pel.jenis = 'IGD'
					$where
				GROUP BY
					pel.id
				";
			$kon->sql = $sql;
			$kon->execute();
			$lama[$i] = $kon->getOne();
			if(!$lama[$i][jml_lama]) $lama[$i][jml_lama] = 0;

			$_SESSION[igd][statistik_kunjungan_igd][jml_baru][$i] = $baru[$i][jml_baru];
			$_SESSION[igd][statistik_kunjungan_igd][jml_lama][$i] = $lama[$i][jml_lama];
			$_SESSION[igd][statistik_kunjungan_igd][tgl_periksa][$i] = $tgl_periksa[$i];
		}
		//$objResponse->addAlert(print_r($lama));
		$_SESSION[igd][statistik_kunjungan_igd][title] = $title . "\nPeriode " . tanggalIndo($tgl_start, "j F Y") . " s.d. " . tanggalIndo($tgl_end, "j F Y");
		$labelx = @array_unique($label_x);
		$_SESSION[igd][statistik_kunjungan_igd][label_x] = @implode(", ",$labelx);

		$table = new Table;
		$table->scroll = false;
		//$table->Th[0][] = "Pelayanan";
		//$table->extra_th[0][] = "rowspan=\"2\"";
		for($i=0;$i<=$selisih;$i++) {
			$table->Th[0][] = $tgl_periksa[$i];
			$table->extra_th[0][] = "colspan=\"2\"";
		}
		$table->Th[0][] = "Jumlah";
		$table->extra_th[0][] = "colspan=\"2\"";
		$kolom = $selisih*2+1;
		for($i=0;$i<=$kolom;$i++) {
			if($i%2 == 0) {
				$table->Th[1][] = "Lama";
			} else $table->Th[1][] = "Baru";
		}
		//kolom jumlah
		$table->Th[1][] = "Lama";
		$table->Th[1][] = "Baru";

		//isinya
		//$table->Row[0][0] = "IGD";
		for($i=0;$i<=$selisih;$i++) {
			$table->Row[0][] = $lama[$i][jml_lama];
			$table->Row[0][] = $baru[$i][jml_baru];
			$jumlah[lama] += $lama[$i][jml_lama];
			$jumlah[baru] += $baru[$i][jml_baru];
		}

		//kolom terakhir
		$table->Row[0][] = $jumlah[lama];
		$table->Row[0][] = $jumlah[baru];
		$ret = $table->build();

		$_SESSION[igd][statistik_kunjungan_igd][th_0] = $table->Th[0];
		$_SESSION[igd][statistik_kunjungan_igd][th_1] = $table->Th[1];
		$_SESSION[igd][statistik_kunjungan_igd][extra_th_0] = $table->extra_th[0];
		$_SESSION[igd][statistik_kunjungan_igd][row] = $table->Row[0];
		
		$objResponse->addAssign("list_data", "innerHTML", $ret);
		$_SESSION[igd][statistik_kunjungan_igd][graph] = "<img src=\"" . URL . "igd/statistik_kunjungan_igd_graph_bar/?md5=".md5(date("Ymdhis"))."\" alt=\"Kunjungan\" />";
		$_SESSION[igd][statistik_kunjungan_igd][title] = $title;
		$objResponse->addAssign("title", "innerHTML", nl2br($_SESSION[igd][statistik_kunjungan_igd][title]));
		$objResponse->addAssign("graph", "innerHTML", $_SESSION[igd][statistik_kunjungan_igd][graph]);
		return $objResponse;
	}
 $pdf->AddPage();
 $pdf->SetFillColor(255, 255, 255);
 $pdf->SetFont('Arial', '', 6);
 //ukuran tulisan
 //tutup tampilan setting
 //isi tabel dan tabelnya
 $no = 0;
 $sql = "select * from " . $dbname . ".sdm_daftarasset where kodeorg in (select distinct kodeorganisasi from " . $dbname . ".organisasi where induk='" . $kdOrg . "') " . $where . " order by kodeasset";
 //$sql="select * from ".$dbname.".sdm_daftarasset where tipeasset='".$kdAst."' and kodeorg='".$kdOrg."' order by kodeorg";
 //echo $sql;
 $qDet = mysql_query($sql) or die(mysql_error());
 while ($res = mysql_fetch_assoc($qDet)) {
     $no += 1;
     $tgl1 = $res['awalpenyusutan'] . "-01";
     $tgl2 = $kdAst . "-02";
     $selisih = datediff($tgl1, $tgl2);
     if ($selisih[months_total] > $res['jlhblnpenyusutan']) {
         $selisih[months_total] = $res['jlhblnpenyusutan'];
     }
     #periksa siapa lebih besar
     if ($tgl1 > $tgl2) {
         $selisih[months_total] = 0;
     }
     $sisabln = $res['jlhblnpenyusutan'] - $selisih[months_total];
     if (substr($sisabln, 0, 1) == '-') {
         $sisabln = 0;
     }
     $akumulasiBulanan = $res['bulanan'] * $selisih[months_total];
     if ($akumulasiBulanan > $res['hargaperolehan']) {
         $akumulasiBulanan = $res['hargaperolehan'];
     }
	function get_kunjungan($val) {
		unset($_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter]);
		$tgl_start = @date("Y-m-d", @mktime(1,1,1,$val[tgl_periksa_bln_start], $val[tgl_periksa_tgl_start], $val[tgl_periksa_thn_start]));
		$tgl_end = @date("Y-m-d", @mktime(1,1,1,$val[tgl_periksa_bln_end], $val[tgl_periksa_tgl_end], $val[tgl_periksa_thn_end]));
		$title = "Rata-rata Jumlah Pasien Kunjungan Poliklinik per Dokter";
		
		if($val[tampilkan] == "hari") {
			$selisih = datediff('d', $tgl_start, $tgl_end);
		} elseif($val[tampilkan] == "bulan") {
			$selisih = datediff('m', $tgl_start, $tgl_end);
		} else {
			$selisih = datediff('y', $tgl_start, $tgl_end);
		}
		if($val[tampilkan] == "hari") {
			$tanggal_awal = tanggalIndo($tgl_start, "j F Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "j F Y");
		} elseif($val[tampilkan] == "bulan") {
			$tanggal_awal = tanggalIndo($tgl_start, "F Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "F Y");
		} else {
			$tanggal_awal = tanggalIndo($tgl_start, "Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "Y");
		}

		$title .= "\nPeriode " . $tanggal_awal . " s.d. " . $tanggal_akhir;

		$arr_tgl_start = explode("-",$tgl_start);
		$tgl_start_tgl = $arr_tgl_start[2];
		$tgl_start_bln = $arr_tgl_start[1];
		$tgl_start_thn = $arr_tgl_start[0];

		$arr_tgl_end = explode("-",$tgl_end);
		$tgl_end_tgl = $arr_tgl_end[2];
		$tgl_end_bln = $arr_tgl_end[1];
		$tgl_end_thn = $arr_tgl_end[0];

		$objResponse = new xajaxResponse();
		$kon = new Konek;
	
		for($i=0;$i<=$selisih;$i++) {
			if($val[tampilkan] == "hari") {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, $tgl_start_bln, ($i+$tgl_start_tgl), $tgl_start_thn));
				$data[$i][tgl_periksa] = tanggalIndo($tgl[$i], "j F Y");
				$_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][label_tick][$i] = @date("j", @mktime(1, 1, 1,$tgl_start_bln, ($tgl_start_tgl+$i), $tgl_start_thn));
				$label_x[$i] = @date("M Y", @mktime(1, 1, 1, $tgl_start_bln, ($tgl_start_tgl+$i), $tgl_start_thn));
				$where = " AND DATE(kk.tgl_daftar) <= '" . $tgl[$i] . "' AND (DATE(kk.tgl_keluar) >= '".$tgl[$i]."' OR kk.tgl_keluar IS NULL)";
			} elseif($val[tampilkan] == "bulan") {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$data[$i][tgl_periksa] = tanggalIndo($tgl[$i], "F Y");
				$_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][label_tick][$i] = @date("M y", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$label_x[$i] = @date("Y", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$where = " AND EXTRACT(YEAR_MONTH FROM kk.tgl_daftar) <= EXTRACT(YEAR_MONTH FROM '" . $tgl[$i] . "')  AND (EXTRACT(YEAR_MONTH FROM kk.tgl_keluar) >= EXTRACT(YEAR_MONTH FROM '" . $tgl[$i] . "') OR kk.tgl_keluar IS NULL)";
			} else {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, 1, 1, ($tgl_start_thn + $i)));
				$data[$i][tgl_periksa] = tanggalIndo($tgl[$i], "Y");
				$_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][label_tick][$i] = @date("Y", @mktime(1, 1, 1, 1, 1, ($tgl_start_thn+$i)));
				$label_x[$i] = "Tahun";
				$where = " AND YEAR(kk.tgl_daftar) = YEAR('" . $tgl[$i] . "')  AND (YEAR(kk.tgl_keluar) >= YEAR('" . $tgl[$i] . "') OR kk.tgl_keluar IS NULL)";
			}
			$sql = "
				SELECT
					kk.dokter_id as dokter_id,
					COUNT(kk.id) as jml_px
				FROM
					kunjungan_kamar kk 
					JOIN kamar kmr ON (kmr.id = kk.kamar_id)
					JOIN pelayanan pel ON (pel.id = kmr.pelayanan_id)
				WHERE
					pel.jenis = 'RAWAT JALAN'
					$where
				GROUP BY
					kk.dokter_id
				ORDER BY
					kk.dokter_id
				";
			$kon->sql = $sql;
			$kon->execute();
			$baru[$i] = $kon->getAll();
		}
		$_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][title] = $title . "\nPeriode " . tanggalIndo($tgl_start, "j F Y") . " s.d. " . tanggalIndo($tgl_end, "j F Y");
		$labelx = @array_unique($label_x);
		$_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][label_x] = @implode(", ",$labelx);
		$new = array();
		for($i=0;$i<sizeof($baru);$i++) {
			if(empty($baru[$i])) {
				$new[jml_px][$i] = 0;
				$new[jml_dokter][$i] = 0;
			} else {
				for($s=0;$s<sizeof($baru[$i]);$s++) {
					if($baru[$i][$s][dokter_id] == $baru[$i][$s-1][dokter_id]) {
						$new[jml_dokter][$i] += 1;
						$new[jml_px][$i] += $baru[$i][$s][jml_px];
					} else {
						//bikin embok
						$new[jml_dokter][$i] += 1;
						$new[jml_px][$i] += $baru[$i][$s][jml_px];
					}
				}
			}
		}

		//print_r($new);
		$table = new Table;
		$table->scroll = false;
		$table->addExtraTh("style=\"width:300px;\"");
		$table->Th[0][] = "Parameter/ Periode";
		$table->Th[1][] = "1";
		for($i=0;$i<=$selisih;$i++) {
			$table->Th[0][] = $data[$i][tgl_periksa];
			$table->Th[1][] = ($i+2);
		}
		$_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][th_0] = $table->Th[0];
		$_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][th_1] = $table->Th[1];

		$table->Row[0][] = "Rata-rata Jumlah Kunjungan Poliklinik/Dokter";
		$table->Row[1][] = "Jumlah Dokter Poliklinik";
		$table->Row[2][] = "Jumlah Kunjungan Poliklinik";
		for($i=0;$i<sizeof($new[jml_dokter]);$i++) {
			//rata-rata
			$table->Row[0][] = @round($new[jml_px][$i]/$new[jml_dokter][$i]);
			//jumlah dokter
			$table->Row[1][] = $new[jml_dokter][$i];
			$table->Row[2][] = $new[jml_px][$i];
			$_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][rata][$i] = @round($new[jml_px][$i]/$new[jml_dokter][$i]);
		}
		$_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][row] = $table->Row;

		$_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][jml_dokter] = $new[jml_dokter];
		$_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][jml_px] = $new[jml_px];

		$ret = $table->build();
		$objResponse->addAssign("list_data", "innerHTML", $ret);
		$_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][graph] = "<img src=\"" . URL . "rekmed/rekap_kunjungan_rajal_per_dokter_graph_line/?md5=".md5(date("Ymdhis"))."\" alt=\"Kunjungan\" />";
		$_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][title] = $title;
		$objResponse->addAssign("title", "innerHTML", nl2br($_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][title]));
		$objResponse->addAssign("graph", "innerHTML", $_SESSION[rekmed][rekap_kunjungan_rajal_per_dokter][graph]);
		return $objResponse;
	}
     $canParse = false;
 }
 //override TV
 $overrideParse = $res->getTVValue('gsm09_include');
 if ($overrideParse == "yes") {
     $canParse = true;
 }
 if ($canParse) {
     $id = $res->get('id');
     $x['url'] = $modx->makeUrl($id, '', '', 'full');
     /* Get the date */
     $date = $res->get('editedon') ? $res->get('editedon') : $res->get('createdon');
     $date = date("Y-m-d", strtotime($date));
     $x['date'] = $date;
     /* Get the date difference */
     $datediff = datediff("d", $date, date("Y-m-d"));
     if ($datediff <= 1) {
         $x['priority'] = '1.0';
         $x['update'] = 'daily';
     } elseif ($datediff > 1 && $datediff <= 7) {
         $x['priority'] = '0.75';
         $x['update'] = 'weekly';
     } elseif ($datediff > 7 && $datediff <= 30) {
         $x['priority'] = '0.50';
         $x['update'] = 'weekly';
     } else {
         $x['priority'] = '0.25';
         $x['update'] = 'monthly';
     }
     //override changefreq
     $overrideChangefreq = $res->getTVValue('gsm09_changefreq');
	function get_kunjungan($val) {
		unset($_SESSION[rekmed][rekap_kunjungan_antar_bangsal]);
		$tgl_start = @date("Y-m-d", @mktime(1,1,1,$val[tgl_periksa_bln_start], $val[tgl_periksa_tgl_start], $val[tgl_periksa_thn_start]));
		$tgl_end = @date("Y-m-d", @mktime(1,1,1,$val[tgl_periksa_bln_end], $val[tgl_periksa_tgl_end], $val[tgl_periksa_thn_end]));
		$title = "Perbandingan Jml Pasien Dirawat Antar Bangsal";
		
		if($val[tampilkan] == "hari") {
			$selisih = datediff('d', $tgl_start, $tgl_end);
		} elseif($val[tampilkan] == "bulan") {
			$selisih = datediff('m', $tgl_start, $tgl_end);
		} else {
			$selisih = datediff('y', $tgl_start, $tgl_end);
		}
		if($val[tampilkan] == "hari") {
			$tanggal_awal = tanggalIndo($tgl_start, "j F Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "j F Y");
		} elseif($val[tampilkan] == "bulan") {
			$tanggal_awal = tanggalIndo($tgl_start, "F Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "F Y");
		} else {
			$tanggal_awal = tanggalIndo($tgl_start, "Y");
			$tanggal_akhir = tanggalIndo($tgl_end, "Y");
		}

		$title .= "\nPeriode " . $tanggal_awal . " s.d. " . $tanggal_akhir;

		$arr_tgl_start = explode("-",$tgl_start);
		$tgl_start_tgl = $arr_tgl_start[2];
		$tgl_start_bln = $arr_tgl_start[1];
		$tgl_start_thn = $arr_tgl_start[0];

		$arr_tgl_end = explode("-",$tgl_end);
		$tgl_end_tgl = $arr_tgl_end[2];
		$tgl_end_bln = $arr_tgl_end[1];
		$tgl_end_thn = $arr_tgl_end[0];

		$objResponse = new xajaxResponse();
		$kon = new Konek;
		$kon->sql = "SELECT pel.id as id, pel.nama as nama, SUM(kmr.jml_bed) as jml_tt FROM pelayanan pel JOIN kamar kmr ON (kmr.pelayanan_id = pel.id) WHERE pel.jenis = 'RAWAT INAP' GROUP BY pel.id";
		$kon->execute();
		$poli = $kon->getAll();
		
		for($i=0;$i<=$selisih;$i++) {
			if($val[tampilkan] == "hari") {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, $tgl_start_bln, ($i+$tgl_start_tgl), $tgl_start_thn));
				$data[$i][tgl_periksa] = tanggalIndo($tgl[$i], "j M\nY");
				$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][label_tick][$i] = @date("j", @mktime(1, 1, 1,$tgl_start_bln, ($tgl_start_tgl+$i), $tgl_start_thn));
				$label_x[$i] = @date("M Y", @mktime(1, 1, 1, $tgl_start_bln, ($tgl_start_tgl+$i), $tgl_start_thn));
				$where = " AND DATE(kk.tgl_daftar) <= '" . $tgl[$i] . "' AND (DATE(kk.tgl_keluar) >= '".$tgl[$i]."' OR kk.tgl_keluar IS NULL)";
			} elseif($val[tampilkan] == "bulan") {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$data[$i][tgl_periksa] = tanggalIndo($tgl[$i], "M\nY");
				$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][label_tick][$i] = @date("M y", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$label_x[$i] = @date("Y", @mktime(1, 1, 1, ($tgl_start_bln+$i), 1, $tgl_start_thn));
				$where = " AND EXTRACT(YEAR_MONTH FROM kk.tgl_daftar) <= EXTRACT(YEAR_MONTH FROM '" . $tgl[$i] . "')  AND (EXTRACT(YEAR_MONTH FROM kk.tgl_keluar) >= EXTRACT(YEAR_MONTH FROM '" . $tgl[$i] . "') OR kk.tgl_keluar IS NULL)";
			} else {
				$tgl[$i] = @date("Y-m-d", @mktime(1, 1, 1, 1, 1, ($tgl_start_thn + $i)));
				$data[$i][tgl_periksa] = tanggalIndo($tgl[$i], "Y");
				$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][label_tick][$i] = @date("Y", @mktime(1, 1, 1, 1, 1, ($tgl_start_thn+$i)));
				$label_x[$i] = "Tahun";
				$where = " AND YEAR(kk.tgl_daftar) = YEAR('" . $tgl[$i] . "')  AND (YEAR(kk.tgl_keluar) >= YEAR('" . $tgl[$i] . "') OR kk.tgl_keluar IS NULL)";
			}
			
			for($s=0;$s<sizeof($poli);$s++) {
				$sql = "
					SELECT
						COUNT(kk.id) as jml
					FROM
						kunjungan_kamar kk 
						JOIN kamar kmr ON (kmr.id = kk.kamar_id)
						JOIN pelayanan pel ON (pel.id = kmr.pelayanan_id)
					WHERE
						pel.id = '".$poli[$s][id]."'
						$where
					GROUP BY
						pel.id
					";
				$kon->sql = $sql;
				$kon->execute();
				$baru[$s][$i] = $kon->getOne();
				if(!$baru[$s][$i][jml]) $baru[$s][$i][jml] = 0;
				
				$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][nama][$s] = $poli[$s][nama];
				$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][jml_tt][$s][$i] = $poli[$s][jml_tt];
				$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][jml][$s][$i] = $baru[$s][$i][jml];
			}
			
			$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][tgl_periksa][$i] = $tgl[$i];
		}
		$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][title] = $title . "\nPeriode " . tanggalIndo($tgl_start, "j F Y") . " s.d. " . tanggalIndo($tgl_end, "j F Y");
		$labelx = @array_unique($label_x);
		$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][label_x] = @implode(", ",$labelx);

		$table = new Table;
		$table->scroll = false;
		$table->Th[0][] = "No";
		$table->Th[0][] = "Bangsal";
		$table->Th[1][] = "1";
		$table->Th[1][] = "2";
		for($i=0;$i<=$selisih;$i++) {
			$table->Th[0][] = $data[$i][tgl_periksa];
			$table->Th[1][] = ($i+3);
		}
		$table->Th[0][] = "Jumlah";
		//$table->Th[0][] = "Jumlah TT";
		$table->Th[1][] = $i+3;
		//$table->Th[1][] = $i+4;
		$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][th_0] = $table->Th[0];
		$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][th_1] = $table->Th[1];

		for($s=0;$s<sizeof($poli);$s++) {
			$table->Row[$s][] = $s+1;
			$table->Row[$s][] = $poli[$s][nama];
			for($i=0;$i<sizeof($baru[$s]);$i++) {
				$table->Row[$s][] = $baru[$s][$i][jml];
				$jml_ver[$i] += $baru[$s][$i][jml];
				$jml_hor[$s] += $baru[$s][$i][jml];
			}
			$table->Row[$s][] = $jml_hor[$s];
			//$table->Row[$s][] = $poli[$s][jml_tt];
			$total += $jml_hor[$s];
			//$total_tt += $poli[$s][jml_tt];
			$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][row][$s] = $table->Row[$s];
		}
		$x = sizeof($poli);
		$table->Row[$x][] = "&nbsp;";
		$table->Row[$x][] = "<b>Jumlah</b>";
		for($i=0;$i<sizeof($baru[$x-1]);$i++) {
			$table->Row[$x][] = $jml_ver[$i];
		}
		$table->Row[$x][] = $total;
		//$table->Row[$x][] = $total_tt;
		$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][last_row] = $table->Row[$x];
		$ret = $table->build();
		$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][tabel] = $ret;
		$objResponse->addAssign("list_data", "innerHTML", $ret);
		$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][graph] = "<img src=\"" . URL . "rekmed/rekap_kunjungan_antar_bangsal_graph_bar/?md5=".md5(date("Ymdhis"))."\" alt=\"Kunjungan\" />";
		$_SESSION[rekmed][rekap_kunjungan_antar_bangsal][title] = $title;
		$objResponse->addAssign("title", "innerHTML", nl2br($_SESSION[rekmed][rekap_kunjungan_antar_bangsal][title]));
		$objResponse->addAssign("graph", "innerHTML", $_SESSION[rekmed][rekap_kunjungan_antar_bangsal][graph]);
		return $objResponse;
	}