$objPHPExcel->getActiveSheet()->getStyle('N' . $RowCount . ':N' . $RowCount)->applyFromArray($styleThinBlackBorderOutline);
 $objPHPExcel->getActiveSheet()->getStyle('O' . $RowCount . ':O' . $RowCount)->applyFromArray($styleThinBlackBorderOutline);
 $objPHPExcel->getActiveSheet()->getStyle('P' . $RowCount . ':P' . $RowCount)->applyFromArray($styleThinBlackBorderOutline);
 $objPHPExcel->getActiveSheet()->getStyle('A' . $RowCount)->getFont()->setBold(true);
 $objPHPExcel->getActiveSheet()->getStyle('P' . $RowCount)->getFont()->setBold(true);
 $objPHPExcel->getActiveSheet()->SetCellValue('A' . $stock_inforamtion, $gTEXT['Stock Information']);
 $styleThinBlackBorderOutline = array('borders' => array('outline' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => 'FF000000'))));
 $objPHPExcel->getActiveSheet()->getStyle('A' . $stock_inforamtion)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
 $objPHPExcel->getActiveSheet()->getStyle('A' . $stock_inforamtion)->getFont()->setBold(true);
 $objPHPExcel->getActiveSheet()->duplicateStyleArray(array('font' => array('size' => '13', 'bold' => true)), 'C3');
 $objPHPExcel->getActiveSheet()->mergeCells('A' . $stock_inforamtion . ':B' . $stock_inforamtion);
 $i = 1;
 $j = $TotalRow;
 $tempGroupId = '';
 while (@($rec = mysql_fetch_array($r))) {
     $objPHPExcel->getActiveSheet()->SetCellValue('A' . $j, $i)->SetCellValue('B' . $j, $rec['ItemName'])->SetCellValue('C' . $j, checkNullable($rec['OpStock_A']))->SetCellValue('D' . $j, checkNullable($rec['ReceiveQty']))->SetCellValue('E' . $j, checkNullable($rec['DispenseQty']))->SetCellValue('F' . $j, checkNullable($rec['AdjustQty']))->SetCellValue('G' . $j, $rec['AdjustReason'])->SetCellValue('H' . $j, $rec['StockoutDays'])->SetCellValue('I' . $j, $rec['StockOutReasonName'])->SetCellValue('J' . $j, checkNullable($rec['ClStock_A']))->SetCellValue('K' . $j, checkNullable($rec['AMC']))->SetCellValue('L' . $j, checkNull(number_format($rec['MOS'], 1)))->SetCellValue('M' . $j, checkNullable($rec['MaxQty']))->SetCellValue('N' . $j, checkNullable($rec['OrderQty'] < 0 ? 0 : $rec['OrderQty']))->SetCellValue('O' . $j, checkNullable($rec['ActualQty'] < 0 ? 0 : $rec['ActualQty']))->SetCellValue('P' . $j, $rec['OUReason']);
     $objPHPExcel->getActiveSheet()->getStyle('A' . $j . ':A' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
     $objPHPExcel->getActiveSheet()->getStyle('B' . $j . ':B' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
     $objPHPExcel->getActiveSheet()->getStyle('C' . $j . ':C' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
     $objPHPExcel->getActiveSheet()->getStyle('D' . $j . ':D' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
     $objPHPExcel->getActiveSheet()->getStyle('E' . $j . ':E' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
     $objPHPExcel->getActiveSheet()->getStyle('F' . $j . ':F' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
     $objPHPExcel->getActiveSheet()->getStyle('G' . $j . ':G' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
     $objPHPExcel->getActiveSheet()->getStyle('H' . $j . ':H' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
     $objPHPExcel->getActiveSheet()->getStyle('I' . $j . ':I' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
     $objPHPExcel->getActiveSheet()->getStyle('J' . $j . ':J' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
     $objPHPExcel->getActiveSheet()->getStyle('K' . $j . ':K' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
     $objPHPExcel->getActiveSheet()->getStyle('L' . $j . ':L' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
     $objPHPExcel->getActiveSheet()->getStyle('M' . $j . ':M' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
     $objPHPExcel->getActiveSheet()->getStyle('N' . $j . ':N' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
     $objPHPExcel->getActiveSheet()->getStyle('O' . $j . ':O' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
Example #2
0
    $sortfield = $_GET['sortdatafield'];
    $sortorder = $_GET['sortorder'];
    if ($sortorder != '') {
        if ($_GET['filterscount'] == 0) {
            if ($sortorder == "desc") {
                $query = "SELECT * from Source  ORDER BY" . " " . $sortfield . " DESC LIMIT {$start}, {$pagesize}";
            } else {
                if ($sortorder == "asc") {
                    $query = "SELECT * from Source ORDER BY" . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                }
            }
        } else {
            if ($sortorder == "desc") {
                $filterquery .= " ORDER BY" . " " . $sortfield . " DESC LIMIT {$start}, {$pagesize}";
            } else {
                if ($sortorder == "asc") {
                    $filterquery .= " ORDER BY" . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                }
            }
            $query = $filterquery;
        }
    }
}
$result = mysql_query($query) or die("SQL Error 1: " . mysql_error());
$courses = null;
// get data and store in a json array
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $courses[] = array('ID' => checkNull($row['ID'], 0), 'Description' => checkNull($row['Description'], ''));
}
$data[] = array('TotalRows' => $total_rows, 'Rows' => $courses);
echo json_encode($data);
Example #3
0
                                } else {
                                    if ($sortorder == "asc") {
                                        $query = "SELECT * from Alert_Details ORDER BY" . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                                    }
                                }
                            } else {
                                if ($sortorder == "desc") {
                                    $filterquery .= " ORDER BY" . " " . $sortfield . " DESC LIMIT {$start}, {$pagesize}";
                                } else {
                                    if ($sortorder == "asc") {
                                        $filterquery .= " ORDER BY" . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                                    }
                                }
                                $query = $filterquery;
                            }
                        }
                    }
                    $result = $mysqli->query($query);
                    $courses = null;
                    // get data and store in a json array
                    while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {
                        $Alert_Details[] = array('ID' => checkNull($row['ID'], 0), 'Description' => checkNull($row['Description'], ''));
                    }
                    $data[] = array('TotalRows' => $total_rows, 'Rows' => $Alert_Details);
                    echo json_encode($data);
                }
            }
        }
    }
}
$mysqli->close();
				$status_sql = "insert into redcap_data_quality_status
				(rule_id, non_rule, project_id, record, event_id, field_name, query_status, assigned_user_id)
				values
				(" . checkNull($rule_id) . ", " . checkNull($non_rule) . ", " . PROJECT_ID . ", '" . prep($result['record']) . "', {$result['event_id']}, " . checkNull($field) . ", " . checkNull($dr_status) . ", " . $assigned_user_id . ")
				on duplicate key update query_status = " . checkNull($dr_status) . ", status_id = LAST_INSERT_ID(status_id)";
				if (!$debug) {
					if (db_query($status_sql)) {
						// Get cleaner_id
						$status_id = db_insert_id();
						// Get current user's ui_id
						$userInitiator = User::getUserInfo(USERID);
						// Add new row to data_resolution_log
						$sql = "insert into redcap_data_quality_resolutions
						(status_id, ts, user_id, response_requested, response, comment, current_query_status, upload_doc_id)
						values
						($status_id, '" . NOW . "', " . checkNull($userInitiator['ui_id']) . ", " . checkNull($response_requested) . ", " . checkNull($response) . ", " . checkNull($rule_info['name']) . ", " . checkNull($dr_status) . ", " . checkNull($_POST['upload_doc_id']) . ")";
						if (db_query($sql)) {
							// Success, so return content via JSON to redisplay with new changes made
							$res_id = db_insert_id();
							## Logging
							// Set data values as json_encoded
							$logDataValues = json_encode(array('res_id' => $res_id, 'record' => $result['record'], 'event_id' => $result['event_id'],
								'field' => $field, 'rule_id' => $rule_id));
							// Set event_id in query string for logging purposes only
							$_GET['event_id'] = $result['event_id'];
							// Log it
							log_event($sql, "redcap_data_quality_resolutions", "MANAGE", $result['record'], $logDataValues, $drw_log);
						} else {
							// ERROR!
							exit('0');
						}
Example #5
0
                                        if ($sortorder == "desc") {
                                            $filterquery .= " ORDER BY" . " " . $sortfield . " DESC LIMIT {$start}, {$pagesize}";
                                        } else {
                                            if ($sortorder == "asc") {
                                                $filterquery .= " ORDER BY" . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                                            }
                                        }
                                        $query = $filterquery;
                                    }
                                }
                            }
                            $result = $mysqli->query($query);
                            $sql = "SELECT FOUND_ROWS() AS `found_rows`;";
                            $rows = $mysqli->query($sql);
                            $totalrow = mysqli_fetch_assoc($rows);
                            $total_rows = $totalrow['found_rows'];
                            $courses = null;
                            // get data and store in a json array
                            while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {
                                $CPD_Details[] = array('ID' => checkNull($row['ID'], 0), 'Name' => checkNull($row['Name'], ''), 'Product_ID' => checkNull($row['Product_ID'], ''), 'Product' => checkNull($row['Product'], ''), 'Category_ID' => checkNull($row['Category_ID'], ''), 'Category' => checkNull($row['Category'], ''), 'Points' => checkNull($row['Points'], ''), 'Accreditation_No' => checkNull($row['Accreditation_No'], ''), 'Dimensions' => checkNull($row['Dimensions'], ''));
                            }
                            $data[] = array('TotalRows' => $total_rows, 'Rows' => $CPD_Details);
                            echo json_encode($data);
                        }
                    }
                }
            }
        }
    }
}
$mysqli->close();
Example #6
0
	/**
	 * @param $record
	 * @param $event_id
	 * @param $group_id
	 * @param $debug
	 */
	public static function schedule_surveys($record, $event_id, $group_id, $debug)
	{
		global $Proj, $project_id, $user_rights, $table_pk;
		/**
		 * if the user is in a DAG
		 */
		if ($user_rights['group_id'] != "") {
			/**
			 * does this record exist?
			 */
			$q = db_query("SELECT 1 from redcap_data WHERE project_id = $project_id AND record = '$record' LIMIT 1");
			if (db_num_rows($q) > 0) {
				/**
				 * is the record in this users DAG?
				 */
				$q = db_query("SELECT 1 from redcap_data WHERE project_id = $project_id AND record = '$record' AND field_name = '__GROUPID__' AND value = '{$user_rights['group_id']}' LIMIT 1");
				if (db_num_rows($q) < 1) {
					/**
					 * record is not in Users DAG!
					 */
					REDCap::logEvent('Scheduled record is not in users DAG', '', '', $record, $event_id, $project_id);
					exit;
				}
			}
		}
		/**
		 * check to see if the subject has an existing schedule on an existing arm
		 */
		$sub = "SELECT DISTINCT e.arm_id from redcap_events_calendar c, redcap_events_metadata e WHERE c.project_id = $project_id AND c.record = '$record' AND c.event_id = e.event_id";
		$sched_arm_result = db_query("SELECT arm_num FROM redcap_events_arms WHERE project_id = $project_id AND arm_id IN (" . pre_query($sub) . ")");
		if ($sched_arm_result) {
			$trt = Prioritize::getTrtInfo($record);
			if ($debug) {
				error_log(print_r($trt, true));
			}
			$tx_start_date = $trt['rfxstdtc'];
			$rand_date = $trt['rand_date'];
			$dates = array();
			$arm_num = db_result($sched_arm_result, 0, 'arm_num');
			if (isset($arm_num) && $arm_num != '') { // subject has an existing schedule. keep existing event_id > arm structure
				if ($arm_num != '1') { // make sure we don't put anything in the first arm
					$q = db_query("SELECT * from redcap_events_metadata m, redcap_events_arms a WHERE a.project_id = $project_id AND a.arm_id = m.arm_id AND a.arm_num = $arm_num order by m.day_offset, m.descrip");
					if ($q) {
						while ($row = db_fetch_assoc($q)) { // if we have no $arm_num, this will be empty
							/**
							 * get the event date ($rand_date for baseline and $tx_start_date + day_offset)
							 */
							$row['day_offset'] = $arm_num != $trt['timing_arm_num'] ? $trt['timing_offsets'][$row['descrip']] : $row['day_offset'];
							if (in_array($row['descrip'], array('Baseline', 'EOT+1Year', 'EOT+3Year'))) {
								$this_event_date = isset($rand_date) && $rand_date != '' ? add_date($rand_date, $row['day_offset']) : null;
							} else {
								$this_event_date = isset($tx_start_date) && $tx_start_date != '' ? add_date($tx_start_date, $row['day_offset']) : null;
							}
							$dates[$row['event_id']] = $this_event_date;
						}
						db_free_result($q);
					}
				} else {
					REDCap::logEvent('Scheduling attempted in invalid arm', '', '', $record, $event_id, $project_id);
				}
			} else { // subject's schedule is new. put dates into event_ids for this arm
				$arm_result = db_query("SELECT arm_num FROM redcap_events_arms WHERE project_id = '$project_id' AND arm_name = '{$trt['arm']}'");
				if ($arm_result) {
					$arm_num = db_result($arm_result, 0, 'arm_num');
					if ($arm_num != '1') {
						$q = db_query("SELECT * from redcap_events_metadata m, redcap_events_arms a WHERE a.project_id = $project_id AND a.arm_id = m.arm_id AND a.arm_num = $arm_num order by m.day_offset, m.descrip");
						if ($q) {
							while ($row = db_fetch_assoc($q)) { // if we have no $arm_num, this will be empty
								/**
								 * get the event date ($rand_date for baseline and $tx_start_date + day_offset)
								 */
								if (in_array($row['descrip'], array('Baseline', 'EOT+1Year', 'EOT+3Year'))) {
									$this_event_date = isset($rand_date) && $rand_date != '' ? add_date($rand_date, $row['day_offset']) : null;
								} else {
									$this_event_date = isset($tx_start_date) && $tx_start_date != '' ? add_date($tx_start_date, $row['day_offset']) : null;
								}
								$dates[$row['event_id']] = $this_event_date;
							}
							db_free_result($q);
						}
					} else {
						REDCap::logEvent('Scheduling attempted in invalid arm', '', '', $record, $event_id, $project_id);
					}
					db_free_result($arm_result);
				}
			}
			if ($debug) {
				error_log(print_r($dates, true));
			}
			if (!empty($dates)) {
				/**
				 * do we have an existing schedule?
				 */
				$sql = "SELECT c.event_date, c.baseline_date, e.* FROM redcap_events_calendar c, redcap_events_metadata e WHERE c.project_id = $project_id AND c.record = '$record' AND c.event_id = e.event_id AND e.arm_id IN (" . pre_query($sub) . ")";
				$sched_result = db_query($sql);
				if ($sched_result) {
					$sql_all = array();
					$sql_errors = array();
					if (db_num_rows($sched_result) > 0) {
						while ($sched_row = db_fetch_assoc($sched_result)) {
							$base_date = in_array($sched_row['descrip'], array('Baseline', 'EOT+1Year', 'EOT+3Year')) ? $trt['rand_date'] : $trt['rfxstdtc'];
							/**
							 * if the scheduled date is in the $dates array, we don't care about it, so ignore it and remove from $dates
							 * if we have an existing schedule and the dates have changed, update the schedule and remove from $dates
							 * if the base date has changed, update it and the schedule
							 * whatever is left will be new dates, insert into schedule
							 */
							if ($dates[$sched_row['event_id']] == $sched_row['event_date']) {
								unset($dates[$sched_row['event_id']]);
							}
							if (isset($dates[$sched_row['event_id']]) && $dates[$sched_row['event_id']] != '' && $sched_row['event_date'] != $dates[$sched_row['event_id']]) { // the date has changed. update the date.
								$sql = "UPDATE redcap_events_calendar SET event_date = '{$dates[$sched_row['event_id']]}' WHERE record = '$record' AND project_id = '$project_id' AND group_id = '$group_id' AND event_id = '{$sched_row['event_id']}' AND event_date = '{$sched_row['event_date']}'";
								if (!$debug) {
									if (db_query($sql)) {
										$sql_all[] = $sql;
										log_event($sql, "redcap_events_calendar", "MANAGE", $record, $sched_row['event_id'], "Update calendar event");
									} else {
										$sql_errors[] = $sql;
									}
								} else {
									error_log($sql);
								}
								unset($dates[$sched_row['event_id']]);
							}
							if ($base_date != $sched_row['baseline_date']) { // the base_date has changed. this will only occur if the treatment start date or randomization date are changed in the study.
								$sql = "UPDATE redcap_events_calendar SET baseline_date = '" . prep($base_date) . "' WHERE record = '$record' AND project_id = '$project_id' AND group_id = '$group_id' AND event_id = '{$sched_row['event_id']}' AND baseline_date = '{$sched_row['baseline_date']}'";
								if (!$debug) {
									if (db_query($sql)) {
										$sql_all[] = $sql;
										log_event($sql, "redcap_events_calendar", "MANAGE", $record, $sched_row['event_id'], "Update calendar event");
									} else {
										$sql_errors[] = $sql;
									}
								} else {
									error_log($sql);
								}
								unset($dates[$sched_row['event_id']]);
							}
						}
						foreach ($dates AS $date_event_id => $date) { //Loop through dates and add them to the schedule
							$base_date = in_array($Proj->eventInfo[$date_event_id]['name'], array('Baseline', 'EOT+1Year', 'EOT+3Year')) ? $trt['rand_date'] : $trt['rfxstdtc'];
							if (isset($date) && $date != "") { //Add to table
								$sql = "INSERT INTO redcap_events_calendar (record, project_id, group_id, event_id, event_date, event_time, event_status, baseline_date) VALUES ('$record', $project_id, " . checkNull($group_id) . ", '" . prep($date_event_id) . "', '" . prep($date) . "', '" . null . "', 0, '$base_date')";
								if (!$debug) {
									if (db_query($sql)) {
										$sql_all[] = $sql;
									} else {
										$sql_errors[] = $sql;
									}
								} else {
									error_log($sql);
								}
							}
						}
						log_event(implode(";\n", $sql_all), "redcap_events_calendar", "MANAGE", $_GET['idnumber'], "$table_pk = '$record'", "Perform scheduling");
					} else {
						foreach ($dates AS $date_event_id => $date) { //Loop through dates and add them to the schedule
							$base_date = in_array($Proj->eventInfo[$date_event_id]['name'], array('Baseline', 'EOT+1Year', 'EOT+3Year')) ? $trt['rand_date'] : $trt['rfxstdtc'];
							if (isset($date) && $date != "") { //Add to table
								$sql = "INSERT INTO redcap_events_calendar (record, project_id, group_id, event_id, event_date, event_time, event_status, baseline_date) VALUES ('$record', $project_id, " . checkNull($group_id) . ", '" . prep($date_event_id) . "', '" . prep($date) . "', '" . null . "', 0, '$base_date')";
								if (!$debug) {
									if (db_query($sql)) {
										$sql_all[] = $sql;
									} else {
										$sql_errors[] = $sql;
									}
								} else {
									error_log($sql);
								}
							}
						}
						log_event(implode(";\n", $sql_all), "redcap_events_calendar", "MANAGE", $_GET['idnumber'], "$table_pk = '$record'", "Perform scheduling");
					}
				}
				db_free_result($sched_result);
			}
			db_free_result($sched_arm_result);
		}
	}
                                $query = "SELECT * from Adviser_Groups ORDER BY" . " " . $sortfield . " DESC LIMIT {$start}, {$pagesize}";
                            } else {
                                if ($sortorder == "asc") {
                                    $query = "SELECT * from Adviser_Groups ORDER BY" . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                                }
                            }
                        } else {
                            if ($sortorder == "desc") {
                                $filterquery .= " ORDER BY" . " " . $sortfield . " DESC LIMIT {$start}, {$pagesize}";
                            } else {
                                if ($sortorder == "asc") {
                                    $filterquery .= " ORDER BY" . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                                }
                            }
                            $query = $filterquery;
                        }
                    }
                }
                $result = $mysqli->query($query);
                $courses = null;
                // get data and store in a json array
                while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
                    $courses[] = array('ID' => checkNull($row['ID'], 0), 'Group_Description' => checkNull($row['Group_Description'], ''), 'Licensee' => $row['Licensee'], 'Licensee_Email' => $row['Licensee_Email']);
                }
                $data[] = array('TotalRows' => $total_rows, 'Rows' => $courses);
                echo json_encode($data);
            }
        }
    }
}
$mysqli->close();
                                                                    $filterquery .= " ORDER BY" . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                                                                }
                                                            }
                                                            $query = $filterquery;
                                                        }
                                                    }
                                                }
                                                $result = $mysqli->query($query);
                                                $sql = "SELECT FOUND_ROWS() AS `found_rows`;";
                                                $rows = $mysqli->query($sql);
                                                $totrows = mysqli_fetch_array($rows, MYSQLI_ASSOC);
                                                $total_rows = $totrows['found_rows'];
                                                $advisers = array();
                                                // get data and store in a json array
                                                while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
                                                    $advisers[] = array('ID' => checkNull($row['ID'], 0), 'Adviser_ID' => checkNull($row['Adviser_ID'], ''), 'AR_Number' => checkNull($row['AR_Number'], ''), 'Given_Name' => checkNull($row['Given_Name'], ''), 'Surname' => checkNull($row['Surname'], ''), 'DOB' => checkNull($row['DOB'], ''), 'PostCode' => checkNull($row['PostCode'], ''), 'Email' => checkNull($row['Email'], ''), 'Phone' => checkNull($row['Phone'], ''), 'Mobile' => checkNull($row['Mobile'], ''), 'Group_ID' => checkNull($row['Group_ID'], ''), 'Group' => checkNull($row['Group_Description'], ''), 'Expertise_Areas' => checkNull($row['Expertise_Areas'], ''), 'ASIC_Areas' => checkNull($row['ASIC_Areas'], ''), 'Referral' => checkNull($row['Referral'], ''), 'Licensee' => checkNull($row['Licencee'], ''), 'Practice_Name' => checkNull($row['Practice_Name'], ''));
                                                }
                                                $data[] = array('TotalRows' => $total_rows, 'Rows' => $advisers);
                                                echo json_encode($data);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Example #9
0
<?php

include "top.php";
$fName = $_POST["fName"];
$lName = $_POST["lName"];
$eMail = $_POST["wEmail"];
checkNull($eMail, "wEmail");
$pwd = base64_encode(gzdeflate($_POST["pswd"]));
require 'model/database.php';
$con = connect();
insert($con, "INSERT INTO `student`(`firstName`, `lastName`, `email`, `password`) values('{$fName}','{$lName}','{$eMail}','{$pwd}')");
close($con);
function checkNull($input, $fieldName)
{
    if ($input == null) {
        throw new Exception("Please enter value for " . $fieldName);
    }
}
?>
<div id="content">
	<div id="box1">

	Thank you for signing up! Welcome <?php 
echo $fName;
?>
. Please <a href = "index.php">Login</a>
	</div>
	<div id = "box2">
	</div>
	<br class="clear" />
</div>
function FacilityDataEntryReportPDF($conn)
{
    global $gTEXT;
    global $SITETITLE;
    $Year = isset($_REQUEST['Year']) ? $_REQUEST['Year'] : '';
    $Month = isset($_REQUEST['Month']) ? $_REQUEST['Month'] : '';
    $RegionId = isset($_REQUEST['RegionId']) ? $_REQUEST['RegionId'] : '';
    $RegionName = isset($_REQUEST['RegionName']) ? $_REQUEST['RegionName'] : '';
    $MonthName = isset($_REQUEST['MonthName']) ? $_REQUEST['MonthName'] : '';
    $ItemGroupName = isset($_REQUEST['ItemGroupName']) ? $_REQUEST['ItemGroupName'] : '';
    $lastyear = getYearForLastMonth($Year, $Month);
    $lastmonth = getLastMonth($Year, $Month);
    $CFMStockId = isset($_REQUEST['CFMStockId']) ? $_REQUEST['CFMStockId'] : '';
    $CountryId = isset($_REQUEST['CountryId']) ? $_REQUEST['CountryId'] : '';
    //$DistrictId = isset($_REQUEST['DistrictId']) ? $_REQUEST['DistrictId'] : '';
    //$OwnerTypeId = isset($_REQUEST['OwnerTypeId']) ? $_REQUEST['OwnerTypeId'] : '';
    $Year = isset($_REQUEST['YearId']) ? $_REQUEST['YearId'] : '';
    $MonthId = isset($_REQUEST['MonthId']) ? $_REQUEST['MonthId'] : '';
    $MonthName = isset($_REQUEST['MonthName']) ? $_REQUEST['MonthName'] : '';
    $FacilityId = isset($_REQUEST['FacilityId']) ? $_REQUEST['FacilityId'] : '';
    require_once 'tcpdf/tcpdf.php';
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
        require_once dirname(__FILE__) . '/lang/eng.php';
        $pdf->setLanguageArray($l);
    }
    $pdf->SetDisplayMode('fullpage', 'SinglePage', 'UseNone');
    $pdf->SetFont('times', 'B', 20);
    $pdf->AddPage('L', 'A4');
    $sqlf = " SELECT FacilityId, FacilityName FROM t_facility WHERE FacilityId={$FacilityId}";
    $resultf = mysql_query($sqlf);
    $FacilityName = '';
    while ($row = mysql_fetch_array($resultf)) {
        $FacilityName = $row['FacilityName'];
    }
    $html3 = '<div class="padding-md clearfix" style="text-align:center;">
					<h2 style="text-align:center;">' . $SITETITLE . '</h2>
					<h4 style="text-align:center;">' . $gTEXT['Facility Level Patient And Stock Status List'] . '</h4>
					<h5 style="text-align:center;">' . $gTEXT['Facility'] . ': ' . $FacilityName . ',
					' . $gTEXT['Month'] . ': ' . $MonthName . ', 
					' . $gTEXT['Year'] . ': ' . $Year . '<h5>
			  </div>';
    $pdf->SetFont('dejavusans', '', 9);
    $pdf->writeHTMLCell(140, 20, 75, 10, $html3, '', 0, 0, false, 'C', true);
    //===============================facility data entry Table======================================
    function checkNullable($value)
    {
        $retVal = '';
        if ($value == 0) {
            $retVal = '';
        } else {
            $retVal = number_format($value);
        }
        return $retVal;
    }
    function checkNull($value)
    {
        $retVal = '';
        if ($value == 0) {
            $retVal = '';
        } else {
            $retVal = $value;
        }
        return $retVal;
    }
    $sql1 = " SELECT\n\t  b.CFMPOId,\n\t  a.FormulationName    PatientTypeName,\n\t  b.RefillPatient,\n\t  b.NewPatient,\n\t  b.TotalPatient\n\tFROM t_formulation a\n\t  INNER JOIN t_cfm_patientoverview b\n\t\tON a.FormulationId = b.FormulationId\n\tWHERE b.CFMStockId = {$CFMStockId}\n\t\tAND FacilityId = {$FacilityId}\n\t\tAND MonthId = {$MonthId}\n\t\tAND YEAR = '" . $Year . "'\n\t\tAND CountryId = {$CountryId}\n\tORDER BY b.CFMPOId ASC";
    $result = mysql_query($sql1);
    $total = mysql_num_rows($result);
    $sql7 = " SELECT CFMStockId, FacilityId, MonthId, Year, \n\t(SELECT b.name FROM  ykx9st_users b WHERE b.username = a.CreatedBy) CreatedBy, DATE_FORMAT(CreatedDt, '%d-%b-%Y %h:%i %p') CreatedDt,\n\t(SELECT b.name FROM  ykx9st_users b WHERE b.username = a.LastUpdateBy)  LastUpdateBy,\t\n\t(SELECT b.name FROM ykx9st_users b WHERE b.username = a.LastSubmittedBy) LastSubmittedBy ,\n\tc.StatusId, c.StatusName,\n\tDATE_FORMAT(LastUpdateDt, '%d-%b-%Y %h:%i %p') LastUpdateDt,\t\n\tDATE_FORMAT(LastSubmittedDt, '%d-%b-%Y %h:%i %p') LastSubmittedDt,\t\n\tDATE_FORMAT(a.AcceptedDt, '%d-%b-%Y %h:%i %p')  AcceptedDt,\t\n\t(SELECT b.name FROM ykx9st_users b WHERE b.username = a.PublishedBy) PublishedBy ,\n\tDATE_FORMAT(a.PublishedDt, '%d-%b-%Y %h:%i %p')  PublishedDt \t\n\tFROM t_cfm_masterstockstatus a LEFT JOIN t_status c ON a.StatusId = c.StatusId ";
    $sql7 .= " WHERE FacilityId = " . $FacilityId . " and MonthId = " . $MonthId . " and Year = '" . $Year . "' AND CountryId = {$CountryId} ";
    $result7 = mysql_query($sql7);
    $sql = "SELECT a.CFMStockStatusId, a.FacilityId, a.MonthId, a.Year, a.ItemGroupId, b.ItemSL, a.ItemNo, b.ItemName, OpStock OpStock_A, a.OpStock_C, a.ReceiveQty, a.DispenseQty, a.AdjustQty, a.AdjustId AdjustReason";
    $sql .= ",a.StockoutDays, a.StockOutReasonId, a.ClStock ClStock_A, a.ClStock_C, a.ClStockSourceId, a.MOS, a.AMC, a.AMC_C, a.AmcChangeReasonId, a.MaxQty, a.OrderQty, a.ActualQty, a.OUReasonId, \n\t a.UserId, a.LastEditTime, c.ProductSubGroupName FormulationName FROM t_cfm_stockstatus a, t_itemlist b, t_product_subgroup c ";
    $sql .= " WHERE a.CFMStockId = {$CFMStockId}\n\t\t\t\tAND `YEAR` = '{$Year}'\n\t\t\t\tAND MonthId = {$MonthId}\n\t\t\t\tAND CountryId = 1\n\t\t\t\tAND a.FacilityId =  {$FacilityId}\n\t\t\t\tAND a.ItemNo = b.ItemNo\n\t\t\t\tAND b.ProductSubGroupId = c.ProductSubGroupId ";
    $sql .= " ORDER BY b.ItemSL asc";
    $r = mysql_query($sql);
    $total = mysql_num_rows($r);
    if ($total > 0) {
        $data = array();
        $i = 0;
        $getRegimen = '';
        $htmlPrint1 = '';
        while ($row = mysql_fetch_array($result)) {
            $htmlPrint1 .= '<tr nobr="true">
				  <td style="text-align: left; word-wrap: break-word; width:30px;">' . ++$i . '</td>
				  <td style="text-align: left; word-wrap: break-word; width:100px;">' . $row['PatientTypeName'] . '</td>
				  <td style="text-align: right; width:40px;">' . checkNullable($row['TotalPatient']) . '</td>
			 </tr>';
        }
        $htmlC1 = '
	<style>
	.cl{clear:both;}
	.col4 {
		width: 260px;
		height: auto;
		float: left;
		overflow: hidden;
		padding: 20px;
		background: #00CCCC;
		font-size:10px;
		clear: left;
		}
	.col4 table, th, td {
		border: 1px solid black;
		padding: 2px;
	}
        
        .printw {
    height: auto;
    margin: 0 auto 50px;
    overflow: hidden;
    width: 1000px;
	}
	</style>       
	<div class="col4">
		<table  style="width: 200px;">
			<tr>
			 <th style="text-align: left; word-wrap: break-word; width:170px;" colspan="3">
                         ' . $gTEXT['Malaria case summary level'] . '</th> 
			</tr>
			<tr>
				<th style="text-align: left; width:30px;">' . $gTEXT['SL'] . '</th> 
				<th style="text-align: left; width:100px;">' . $gTEXT['Case Type'] . '</th> 
				<th style="text-align: left; width:40px;">' . $gTEXT['Total'] . '</th>
			</tr>
			' . $htmlPrint1 . '
		</table>
	</div>';
        $sql1 = " SELECT\n\t\t\t  b.CFMPatientStatusId,\n\t\t\t  c.FormulationId,\n\t\t\t  c.FormulationName,\n\t\t\t  b.RegimenId,\n\t\t\t  d.RegimenName RegimenMasterName,\n\t\t\t  a.GenderTypeId,\n\t\t\t  b.RefillPatient,\n\t\t\t  b.NewPatient,\n\t\t\t  b.TotalPatient\n\t\t\tFROM t_regimen a\n\t\t\t  INNER JOIN t_cfm_regimenpatient b\n\t\t\t    ON a.RegimenId = b.RegimenId\n\t\t\t  INNER JOIN t_formulation c\n\t\t\t    ON a.FormulationId = c.FormulationId\n\t\t\tINNER JOIN t_regimen_master d\n\t\t\t    ON a.RegMasterId = d.RegMasterId\n\t\t\tWHERE b.CFMStockId = {$CFMStockId}\n\t\t\t\tAND FacilityId = {$FacilityId}\n\t\t\t\tAND MonthId = {$MonthId}\n\t\t\t\tAND `Year` = '{$Year}'\n\t\t\t\tAND CountryId = {$CountryId}\n\t\t\tORDER BY c.FormulationName, b.RegimenId, a.GenderTypeId  desc";
        $result1 = mysql_query($sql1);
        $total = mysql_num_rows($result1);
        $tmpFormulationId = -1;
        $i = 0;
        $htmlPrint2 = '';
        while (@($row = mysql_fetch_array($result1))) {
            if ($tmpFormulationId != @$row['FormulationId']) {
                if ($i > 0) {
                    $htmlPrint2 .= '</tr>';
                }
                $htmlPrint2 .= '<tr nobr="true">
				  <td style="text-align: left; word-wrap: break-word; width:30px;">' . ++$i . '</td>
				  <td style="text-align: left; word-wrap: break-word; width:250px;">' . @$row['FormulationName'] . '</td>';
                $htmlPrint2 .= '<td style="text-align: right; width:70px;">' . checkNullable(@$row['TotalPatient']) . '</td>';
                $tmpFormulationId = @$row['FormulationId'];
            } else {
                $htmlPrint2 .= '<td style="text-align: right; width:70px;">' . checkNullable(@$row['TotalPatient']) . '</td>';
                $tmpFormulationId = @$row['FormulationId'];
            }
        }
        if ($i > 0) {
            $htmlPrint2 .= '</tr>';
        }
        $htmlC2 = '
	<style>
	.cl{clear:both;}
	.col4 {
		width: 300px;
		height: auto;
		float: left;
		overflow: hidden;
		padding: 20px;
		background: #00CCCC;
		font-size:10px;
		clear: left;
		}
	.col4 table, th, td {
		border: 1px solid black;
		padding: 2px;
	}
	</style>
	<div class="col4">
		<table  style="width: 800px;">
                        <tr>
			 <th style="text-align: left; word-wrap: break-word; width:770px;" colspan="9">
                         ' . $gTEXT['Malaria case details'] . '</th> 
			</tr>

			<tr nobr="true">
				<th style="text-align: left; word-wrap: break-word; width:30px;"></th> 
				<th style="text-align: left; word-wrap: break-word; width:250px;"></th> 
				<th style="text-align: center; width:140px;"  colspan="2">' . $gTEXT['0-4 Years'] . '</th>
				<th style="text-align: center; width:140px;"  colspan="2">' . $gTEXT['5-14 Years'] . '</th>
				<th style="text-align: center; width:140px;"  colspan="2">' . $gTEXT['15+ Years'] . '</th>
				<th style="text-align: left; width:70px;"></th>
			</tr>
			<tr nobr="true">
				<th style="text-align: left; word-wrap: break-word; width:30px;">' . $gTEXT['SL'] . '</th> 
				<th style="text-align: left; word-wrap: break-word; width:250px;">' . $gTEXT['Case Type'] . '</th> 
				<th style="text-align: right; width:70px;">' . $gTEXT['M'] . '</th>
				<th style="text-align: right; width:70px;">' . $gTEXT['F'] . '</th>
				<th style="text-align: right; width:70px;">' . $gTEXT['M'] . '</th>
				<th style="text-align: right; width:70px;">' . $gTEXT['F'] . '</th>
				<th style="text-align: right; width:70px;">' . $gTEXT['M'] . '</th>
				<th style="text-align: right; width:70px;">' . $gTEXT['F'] . '</th>
				<th style="text-align: right; width:70px;">' . $gTEXT['Pregnant Women'] . '</th>
			</tr>
			' . $htmlPrint2 . '
		</table>
	</div>';
        $f = 0;
        $tblHTML = '';
        $tempGroupId = '';
        while (@($rec = mysql_fetch_array($r))) {
            $data['SL'][$f] = $f;
            $data['ItemName'][$f] = @$rec['ItemName'];
            $data['OpStock_A'][$f] = checkNullable(@$rec['OpStock_A']);
            $data['ReceiveQty'][$f] = checkNullable(@$rec['ReceiveQty']);
            $data['ActualQty'][$f] = checkNullable(@$rec['ActualQty']);
            $data['DispenseQty'][$f] = checkNullable(@$rec['DispenseQty']);
            $data['AdjustQty'][$f] = checkNullable(@$rec['AdjustQty']);
            $data['AdjustReason'][$f] = @$rec['AdjustReason'];
            $data['StockoutDays'][$f] = @$rec['StockoutDays'];
            $data['StockOutReasonName'][$f] = @$rec['StockOutReasonName'];
            $data['ClStock_A'][$f] = checkNullable(@$rec['ClStock_A']);
            $data['AMC'][$f] = checkNullable(@$rec['AMC']);
            $data['MOS'][$f] = checkNull(number_format(@$rec['MOS'], 1));
            $data['MaxQty'][$f] = checkNullable(@$rec['MaxQty']);
            $data['OrderQty'][$f] = checkNullable(@$rec['OrderQty'] < 0 ? 0 : @$rec['OrderQty']);
            $data['ActualQty'][$f] = checkNullable(@$rec['ActualQty'] < 0 ? 0 : @$rec['ActualQty']);
            $data['OUReason'][$f] = @$rec['OUReason'];
            $tblHTML .= '<tr style="page-break-inside:avoid;">
            				<td align="center" width="30" valign="middle">' . ($data['SL'][$f] + 1) . '</td>  
                            <td align="left" width="157" valign="middle">' . $data['ItemName'][$f] . '</td>
                            <td align="right" width="50" valign="middle">' . $data['OpStock_A'][$f] . '</td>
                            <td align="right" width="50" valign="middle">' . $data['ReceiveQty'][$f] . '</td> 
                            <td align="right" width="50" valign="middle">' . $data['DispenseQty'][$f] . '</td>
                            <td align="right" width="50" valign="middle">' . $data['AdjustQty'][$f] . '</td>
                            <td align="left" width="55" valign="middle">' . $data['AdjustReason'][$f] . '</td> 
							<td align="right" width="50" valign="middle">' . $data['StockoutDays'][$f] . '</td> 
							<td align="left" width="55" valign="middle">' . $data['StockOutReasonName'][$f] . '</td> 
                            <td align="right" width="50" valign="middle">' . $data['ClStock_A'][$f] . '</td> 
                            <td align="right" width="50" valign="middle">' . $data['AMC'][$f] . '</td>
                            <td align="right" width="50" valign="middle">' . $data['MOS'][$f] . '</td>
                            <td align="right" width="50" valign="middle">' . $data['MaxQty'][$f] . '</td> 
							<td align="right" width="50" valign="middle">' . $data['OrderQty'][$f] . '</td> 
							<td align="right" width="60" valign="middle">' . $data['ActualQty'][$f] . '</td>
							<td align="left" width="100" valign="middle">' . $data['OUReason'][$f] . '</td>  
                    </tr>';
            $f++;
        }
        $headertable = '';
        while (@($row = mysql_fetch_array($result7))) {
            $headertable = '<tr>
						<td align="left" width="80" valign="middle">
						' . $gTEXT['Report Id'] . ' : ' . @$row['CFMStockId'] . '</td>
						<td align="left" width="220" valign="middle">
						' . $gTEXT['Created By'] . ' : ' . @$row['CreatedBy'] . '</td> 
						<td align="left" width="220" valign="middle">
						' . $gTEXT['Last Upadated By'] . ' : ' . @$row['LastUpdateBy'] . '</td>
						<td align="left" width="220" valign="middle">
						' . $gTEXT['Submitted By'] . ' : ' . @$row['LastSubmittedBy'] . '</td>
						<td align="left" width="220" valign="middle">
						' . $gTEXT['Published By'] . ' : ' . @$row['PublishedBy'] . '</td>
				  </tr>
				  <tr>
						<td align="left" width="80" valign="middle">
						<b style="font-size:11px;">' . @$row['StatusName'] . '</b></td>
						<td align="left" width="220" valign="middle">
						' . $gTEXT['Created Date'] . ' : ' . @$row['CreatedDt'] . '</td> 
						<td align="left" width="220" valign="middle">
						' . $gTEXT['Last Updated Date'] . ' : ' . @$row['LastUpdateDt'] . '</td>
						<td align="left" width="220" valign="middle">
						' . $gTEXT['Submitted Date'] . ' : ' . @$row['LastSubmittedDt'] . '</td>
						<td align="left" width="220" valign="middle">
						' . $gTEXT['Published Date'] . ' : ' . @$row['PublishedDt'] . '</td>
				  </tr>';
        }
        $htmlHead = '
            <style>
             td{
                 height: 6px;
                 line-height:3px;
             }
            th{
                height: 20;
                font-size:9px;
            }
		
            </style>
			<div style="margin:0 0 10px 0;">
			<table width="100%" border="0.5" style="margin:0 auto;" class="clearfix">
            	  ' . $headertable . '
			</table>
			</div>
			<div class="clearfix"></div>';
        $htmlC5 = '
            <style>
             td{
                 height: 6px;
                 line-height:3px;
             }
            th{
                height: 20;
                font-size:9px;
            }
		
            </style>
			<div class="clearfix"></div>
                          <div class="col-xs-12" style="font-weight:bold; font-size:14px; padding-left:6px; text-align:left;">' . $gTEXT['Stock Information'] . '</div>
            <table width="100%" border="0.5" style="margin:0 auto;">
                       
                                        <tr>
						<th align="center" width="30" valign="middle">' . $gTEXT['SL'] . '#</th>
						<th align="left" width="157" valign="middle">' . $gTEXT['Item'] . '</th> 
						<th align="right" width="50" valign="middle">' . $gTEXT['OBL (A)'] . '</th>
						<th align="right" width="50" valign="middle">' . $gTEXT['Received (B)'] . '</th>
						<th align="right" width="50" valign="middle">' . $gTEXT['Dispensed (C)'] . '</th> 
						<th align="right" width="50" valign="middle">' . $gTEXT['Adjusted (+-D)'] . '</th> 
						<th align="left" width="55" valign="middle">' . $gTEXT['Adjust Reason'] . '</th>
						<th align="right" width="50" valign="middle">' . $gTEXT['Stock Out Days'] . '</th> 
						<th align="left" width="55" valign="middle">' . $gTEXT['Stock Out Reason'] . '</th> 
						<th align="right" width="50" valign="middle">' . $gTEXT['Closing Balance (E)'] . '</th>
						<th align="right" width="50" valign="middle">' . $gTEXT['AMC (F)'] . '</th> 
						<th align="right" width="50" valign="middle">' . $gTEXT['MOS (G)'] . '</th> 
						<th align="right" width="50" valign="middle">' . $gTEXT['Max Qty (H)'] . '</th>
						<th align="right" width="50" valign="middle">' . $gTEXT['Order Qty (I)'] . '</th> 
						<th align="right" width="60" valign="middle">' . $gTEXT['Actual Order Qty (J)'] . '</th>
						<th align="left" width="100" valign="middle">' . $gTEXT['Order Qty Update Reason'] . '</th> 
            	  </tr>' . $tblHTML . '</table>';
        //echo $htmlC2;
        $pdf->SetFont('dejavusans', '', 7);
        $pdf->writeHTMLCell(0, 50, 10, 40, $htmlHead, '', 0, 0, false, 'C', true);
        $pdf->writeHTMLCell(0, 50, 10, 63, $htmlC1, '', 0, 0, false, 'C', true);
        $pdf->writeHTMLCell(0, 50, 63, 63, $htmlC2, '', 0, 0, false, 'C', true);
        //$pdf->writeHTMLCell(0, 50, 132, 60, $htmlC3, '', 0, 0, false, 'C', true);
        //$pdf->writeHTMLCell(0, 50, 208, 60, $htmlC4, '', 0, 0, false, 'C', true);
        $pdf->writeHTMLCell(0, 50, 10, 140, $htmlC5, '', 0, 0, false, 'C', true);
        //$pdf->writeHTMLCell(0, 50, 10, 290, $htmlC5, '', 0, 0, false, 'C', true);
        //$pdf->Cell(0, 0, $htmlC5, 1, 1, 'C');
        $pdf->endPage();
        $filename = 'Facility_Level_Patient_And_Stock_Status_' . $ItemGroupName . '_' . $MonthName . '_' . $Year . '.pdf';
        $filePath = SITEDOCUMENT . 'administrator/components/com_jcode/source/report/pdfslice/' . $filename;
        if (file_exists($filePath)) {
            unlink($filePath);
        }
        $pdf->Output('pdfslice/' . $filename, 'F');
        echo $filename;
    } else {
        echo 'Processing Error';
    }
}
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE');
header('Content-type: application/json');
include_once 'Connect.php';
include_once 'UtilFunctions.php';
include_once 'class.phpmailer.php';
if (isset($_REQUEST["type"]) && trim($_REQUEST["type"]) == 'DETAILS') {
    $User_ID = $_REQUEST['User_ID'];
    $query = "SELECT a.* \n\t\t\t\t\t\tFROM Clients a \n\t\t\t\t\t\tINNER JOIN Users u ON u.ID = a.User_ID \n\t\t\t\t\t\tWHERE u.User_ID = '" . $User_ID . "' \n\t\t\t\t\t\tLIMIT 1";
    //echo $query;exit;
    $result = $mysqli->query($query);
    $consumer = array();
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
        //echo $row['ID'];
        $consumer[] = array('ID' => checkNull($row['ID'], ''), 'GivenName' => checkNull($row['GivenName'], ''), 'Surname' => checkNull($row['Surname'], ''), 'Email' => checkNull($row['Email'], ''), 'Phone' => checkNull($row['Phone'], ''), 'DOB' => checkNull($row['DOB'], ''), 'PostCode' => checkNull($row['PostCode'], ''));
    }
    getSuccessCreateResponse('', $consumer);
} else {
    if (isset($_REQUEST["type"]) && trim($_REQUEST["type"]) == 'UPD') {
        $userId = $_REQUEST['userID'];
        $Id = $_REQUEST['ID'];
        $GivenName = strtoupper($_REQUEST['GivenName']);
        $Surname = strtoupper($_REQUEST['Surname']);
        $DOB = $_REQUEST['DOB'];
        $PostCode = $_REQUEST['PostCode'];
        //$Email = strtoupper($_REQUEST['Email']);
        $Mobile = $_REQUEST['Mobile'];
        $Password = $_REQUEST['Password'];
        $query = "UPDATE `Clients` SET\n\t\t\t`GivenName` = '" . $GivenName . "' , \n\t\t\t`Surname` = '" . $Surname . "' , \n\t\t\t`DOB` = '" . $DOB . "' , \n\t\t\t`PostCode` = '" . $PostCode . "' ,\n\t\t\t`Last_Updated` = NOW() \t\n\t\tWHERE `ID` = " . $Id;
        $result = $mysqli->query($query);
Example #12
0
foreach ($thing as &$row) {
    $row = str_getcsv($row, ";");
    foreach ($row as &$deeper) {
        $cont = false;
        $deeper = str_getcsv($deeper);
        if (trim($deeper[0]) == "RECALL_NUMBER_NUM") {
            continue;
            //skip the headers
        }
        foreach ($rr as $a) {
            // Check for duplicates from new 60 day recalls
            if ($a['recall_number'] == $deeper[0]) {
                if (checkNull($a['year']) == $deeper[1]) {
                    if (checkNull($a['manufacturer_recall_number']) == $deeper[2]) {
                        if (checkNull($a['make']) == $deeper[5]) {
                            if (checkNull($a['model']) == $deeper[6]) {
                                //match found
                                $cont = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
        if ($cont == true) {
            continue;
        }
        $query = 'INSERT INTO recalls (
                recall_number,
                year, 
Example #13
0
                                                }
                                            }
                                        } else {
                                            if ($sortorder == "desc") {
                                                $filterquery .= " ORDER BY" . " " . $sortfield . " DESC LIMIT {$start}, {$pagesize}";
                                            } else {
                                                if ($sortorder == "asc") {
                                                    $filterquery .= " ORDER BY" . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                                                }
                                            }
                                            $query = $filterquery;
                                        }
                                    }
                                }
                                $result = $mysqli->query($query);
                                $CPD_Articles = array();
                                // get data and store in a json array
                                while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {
                                    $CPD_Articles[] = array('ID' => checkNull($row['ID'], 0), 'Topic_ID' => checkNull($row['Topic_ID'], ''), 'Topic' => checkNull($row['Topic'], ''), 'Summary' => checkNull($row['Summary'], ''), 'CPD_ID' => checkNull($row['CPD_ID'], ''), 'CPD_Quiz' => checkNull($row['CPD_Quiz'], ''), 'PDF_File' => checkNull($row['PDF_File'], ''));
                                }
                                $data[] = array('TotalRows' => $total_rows, 'Rows' => $CPD_Articles);
                                echo json_encode($data);
                            }
                        }
                    }
                }
            }
        }
    }
}
$mysqli->close();
Example #14
0
    if ($sortorder != '') {
        if ($_GET['filterscount'] == 0) {
            if ($sortorder == "desc") {
                $query = "SELECT s.*, DOB as Birthdate,a.Description as Aim_Description, sp.Name as SP_Name, so.Description as SO_Description, s.Group_ID FROM Students s left join Aim a on a.ID = s.Aim left join SalesPerson sp on sp.ID = s.Salesperson left join Source so on so.ID = s.Source_id  ORDER BY" . " " . $sortfield . " DESC LIMIT {$start}, {$pagesize}";
            } else {
                if ($sortorder == "asc") {
                    $query = "SELECT s.*, DOB as Birthdate,a.Description as Aim_Description, sp.Name as SP_Name, so.Description as SO_Description, s.Group_ID FROM Students s left join Aim a on a.ID = s.Aim left join SalesPerson sp on sp.ID = s.Salesperson left join Source so on so.ID = s.Source_id ORDER BY" . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                }
            }
        } else {
            if ($sortorder == "desc") {
                $filterquery .= " ORDER BY" . " " . $sortfield . " DESC LIMIT {$start}, {$pagesize}";
            } else {
                if ($sortorder == "asc") {
                    $filterquery .= " ORDER BY" . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                }
            }
            $query = $filterquery;
        }
    }
}
//echo $query;
$result = $mysqli->query($query);
$students = null;
// get data and store in a json array
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    $students[] = array('StudentNo' => checkNull($row['StudentNo'], 0), 'GivenName' => checkNull($row['GivenName'], ''), 'Surname' => checkNull($row['Surname'], ''), 'Email' => checkNull($row['Email'], ''), 'Address' => checkNull($row['Address'], ''), 'PostCode' => checkNull($row['PostCode'], ''), 'MobilePhone' => checkNull($row['MobilePhone'], ''), 'WorkPhone' => checkNull($row['WorkPhone'], ''), 'HomePhone' => checkNull($row['HomePhone'], ''), 'Occupation' => checkNull($row['Occupation'], ''), 'Experience' => checkNull($row['Experience'], ''), 'Referrer' => checkNull($row['Referrer'], ''), 'Aim' => checkNull($row['Aim_Description'], ''), 'Source' => checkNull($row['SO_Description'], ''), 'Salesperson' => checkNull($row['SP_Name'], ''), 'Salesperson_ID' => checkNull($row['SalesPerson'], ''), 'Notes' => checkNull($row['Notes'], ''), 'Group' => $row['Group_ID'], 'Balance' => checkNull($row['Balance'], 0), 'DOB' => checkNull($row['Birthdate'], ''), 'Collections' => $row['Collectables']);
}
$data[] = array('TotalRows' => $total_rows, 'Rows' => $students);
echo json_encode($data);
$mysqli->close();
                                    $query = "SELECT * from Instructor ORDER BY" . " " . $sortfield . " DESC LIMIT {$start}, {$pagesize}";
                                } else {
                                    if ($sortorder == "asc") {
                                        $query = "SELECT * from Instructor ORDER BY" . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                                    }
                                }
                            } else {
                                if ($sortorder == "desc") {
                                    $filterquery .= " ORDER BY" . " " . $sortfield . " DESC LIMIT {$start}, {$pagesize}";
                                } else {
                                    if ($sortorder == "asc") {
                                        $filterquery .= " ORDER BY" . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                                    }
                                }
                                $query = $filterquery;
                            }
                        }
                    }
                    $result = mysql_query($query) or die("SQL Error 1: " . mysql_error());
                    $courses = null;
                    // get data and store in a json array
                    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                        $courses[] = array('ID' => checkNull($row['ID'], 0), 'Name' => checkNull($row['Name'], ''));
                    }
                    $data[] = array('TotalRows' => $total_rows, 'Rows' => $courses);
                    echo json_encode($data);
                }
            }
        }
    }
}
    $i = 1;
    while ($rec = mysql_fetch_array($r)) {
        echo '<tr>
						  <td style="text-align: center;  width: 50px;">' . $i . '</td>
						  <td style="text-align: left; text-align: left; word-break:break-all; width: 210px;">
						  ' . $rec['ItemName'] . '</td>
						  <td style="text-align: right;">' . checkNullable($rec['OpStock_A']) . '</td>
						  <td style="text-align: right;">' . checkNullable($rec['ReceiveQty']) . '</td>
						  <td style="text-align: right;">' . checkNullable($rec['DispenseQty']) . '</td>
						  <td style="text-align: right;">' . checkNullable($rec['AdjustQty']) . '</td>
						  <td style="text-align: left;">' . $rec['AdjustReason'] . '</td>
						  <td style="text-align: right; word-break:break-all; width: 70px;">' . $rec['StockoutDays'] . '</td>
						  <td style="text-align: left; word-break:break-all; width: 70px;">' . $rec['StockOutReasonName'] . '</td>
						  <td style="text-align: right;">' . checkNullable($rec['ClStock_A']) . '</td>
						  <td style="text-align: right;">' . checkNullable($rec['AMC']) . '</td>
						  <td style="text-align: right;">' . checkNull(number_format($rec['MOS'], 1)) . '</td>
						  <td style="text-align: right;">' . checkNullable($rec['MaxQty']) . '</td>
						  <td style="text-align: right;">' . checkNullable($rec['OrderQty'] < 0 ? 0 : $rec['OrderQty']) . '</td>
						  <td style="text-align: right;">' . checkNullable($rec['ActualQty'] < 0 ? 0 : $rec['ActualQty']) . '</td>
						  <td style="text-align: left; text-align: left; word-break:break-all; width: 90px;">' . $rec['OUReason'] . '</td>
					 </tr>';
        $i++;
    }
    echo '</thead>
			 </table>
			 </div>
			 </div>  
			 </div></div>';
    echo '</body></html>';
} else {
    $error = "No record found";
 public static function storeExportFile($original_filename, $file_content, $archiveFile = false, $dateShiftDates = false)
 {
     global $edoc_storage_option;
     ## Create the stored name of the file as it wll be stored in the file system
     $stored_name = date('YmdHis') . "_pid" . PROJECT_ID . "_" . generateRandomHash(6) . getFileExt($original_filename, true);
     $file_extension = getFileExt($original_filename);
     $mime_type = strtolower($file_extension) == 'csv' ? 'application/csv' : 'application/octet-stream';
     // If file is UTF-8 encoded, then add BOM
     // Do NOT use addBOMtoUTF8() on Stata syntax file (.do) because BOM causes issues in syntax file
     if (strtolower($file_extension) != 'do') {
         $file_content = addBOMtoUTF8($file_content);
     }
     // If Gzip enabled, then gzip the file and append filename with .gz extension
     list($file_content, $stored_name, $gzipped) = gzip_encode_file($file_content, $stored_name);
     // Get file size in bytes
     $docs_size = strlen($file_content);
     // Add file to file system
     if ($edoc_storage_option == '0') {
         // Store locally
         $fp = fopen(EDOC_PATH . $stored_name, 'w');
         if ($fp !== false && fwrite($fp, $file_content) !== false) {
             // Close connection
             fclose($fp);
         } else {
             // Send error response
             return false;
         }
         // Add file to S3
     } elseif ($edoc_storage_option == '2') {
         global $amazon_s3_key, $amazon_s3_secret, $amazon_s3_bucket;
         $s3 = new S3($amazon_s3_key, $amazon_s3_secret, SSL);
         if (!$s3->putObject($file_content, $amazon_s3_bucket, $stored_name, S3::ACL_PUBLIC_READ_WRITE)) {
             // Send error response
             return false;
         }
     } else {
         // Store using WebDAV
         require_once APP_PATH_CLASSES . "WebdavClient.php";
         require APP_PATH_WEBTOOLS . 'webdav/webdav_connection.php';
         $wdc = new WebdavClient();
         $wdc->set_server($webdav_hostname);
         $wdc->set_port($webdav_port);
         $wdc->set_ssl($webdav_ssl);
         $wdc->set_user($webdav_username);
         $wdc->set_pass($webdav_password);
         $wdc->set_protocol(1);
         // use HTTP/1.1
         $wdc->set_debug(false);
         // enable debugging?
         if (!$wdc->open()) {
             // Send error response
             return false;
         }
         if (substr($webdav_path, -1) != '/') {
             $webdav_path .= '/';
         }
         $http_status = $wdc->put($webdav_path . $stored_name, $file_content);
         $wdc->close();
     }
     ## Add file info to edocs_metadata table
     // If not archiving file in File Repository, then set to be deleted in 1 hour
     $delete_time = $archiveFile ? "" : NOW;
     // Add to table
     $sql = "insert into redcap_edocs_metadata (stored_name, mime_type, doc_name, doc_size, file_extension, project_id, \n\t\t\t\tstored_date, delete_date, gzipped) values ('" . prep($stored_name) . "', '{$mime_type}', '" . prep($original_filename) . "', \n\t\t\t\t'" . prep($docs_size) . "', '" . prep($file_extension) . "', " . PROJECT_ID . ", '" . NOW . "', " . checkNull($delete_time) . ", {$gzipped})";
     if (!db_query($sql)) {
         // Send error response
         return false;
     }
     // Get edoc_id
     $edoc_id = db_insert_id();
     ## Add to doc_to_edoc table
     // Set flag if data is date shifted
     $dateShiftFlag = $dateShiftDates ? "DATE_SHIFT" : "";
     // Set "comment" in docs table
     if (strtolower($file_extension) == 'csv') {
         $docs_comment = "Data export file created by " . USERID . " on " . date("Y-m-d-H-i-s");
     } else {
         if ($file_extension == 'sps') {
             $stats_package_name = 'Spss';
         } elseif ($file_extension == 'do') {
             $stats_package_name = 'Stata';
         } else {
             $stats_package_name = camelCase($file_extension);
         }
         $docs_comment = "{$stats_package_name} syntax file created by " . USERID . " on " . date("Y-m-d-H-i-s");
     }
     // Archive in redcap_docs table
     $sql = "INSERT INTO redcap_docs (project_id, docs_name, docs_file, docs_date, docs_size, docs_comment, docs_type, \n\t\t\t\tdocs_rights, export_file, temp) VALUES (" . PROJECT_ID . ", '" . prep($original_filename) . "', NULL, '" . TODAY . "', \n\t\t\t\t'{$docs_size}', '" . prep($docs_comment) . "', '{$mime_type}', " . checkNull($dateShiftFlag) . ", 1, \n\t\t\t\t" . checkNull($archiveFile ? "0" : "1") . ")";
     if (db_query($sql)) {
         $docs_id = db_insert_id();
         // Add to redcap_docs_to_edocs also
         $sql = "insert into redcap_docs_to_edocs (docs_id, doc_id) values ({$docs_id}, {$edoc_id})";
         db_query($sql);
     } else {
         // Could not store in table, so remove from edocs_metadata also
         db_query("delete from redcap_edocs_metadata where doc_id = {$edoc_id}");
         return false;
     }
     // Return successful response of docs_id from redcap_docs table
     return $docs_id;
 }
				on duplicate key update query_status = " . checkNull($dr_status) . ", status_id = LAST_INSERT_ID(status_id)";
				if ($debug) {
					show_var($sql, 'INSERT STATUS', 'red');
				}
				if (true) {
				//if (db_query($sql)) {
					// Get cleaner_id
					$status_id = db_insert_id();
					// Get current user's ui_id
					$userInitiator = User::getUserInfo(USERID);
					// Add new row to data_resolution_log
					$sql = "insert into redcap_data_quality_resolutions (status_id, ts, user_id, response_requested,
					response, comment, current_query_status, upload_doc_id)
					values ($status_id, '" . NOW . "', " . checkNull($userInitiator['ui_id']) . ",
					" . checkNull($response_requested) . ", " . checkNull($response) . ",
					" . checkNull($rule_info['name']) . ", " . checkNull($dr_status) . ", " . checkNull($_POST['upload_doc_id']) . ")";
					if (!$debug) {
						if (db_query($sql)) {
							// Success, so return content via JSON to redisplay with new changes made
							$res_id = db_insert_id();
							## Logging
							// Set data values as json_encoded
							$logDataValues = json_encode(array('res_id' => $res_id, 'record' => $result['record'], 'event_id' => $result['event_id'],
								'field' => $field, 'rule_id' => $rule_id));
							// Set event_id in query string for logging purposes only
							$_GET['event_id'] = $result['event_id'];
							// Log it
							log_event($sql, "redcap_data_quality_resolutions", "MANAGE", $result['record'], $logDataValues, $drw_log);
						} else {
							// ERROR!
							exit('0');
Example #19
0
<?php

session_start();
include "top.php";
require 'model/database.php';
$title = $_POST["title"];
checkNull($title, "title");
$category = $_POST["category"];
$description = $_POST["description"];
if (isset($_POST['offer'])) {
    $offer = $_POST["offer"];
} else {
    checkNull(null, "offer");
}
// echo"file 1:".$_FILES["file"]["name"][0];
// echo"file 2:".$_FILES["file"]["name"][1];
//print_r($_FILES);
$imagesPathInDb = "";
$fileLoc = "";
$allowedExts = array("GIF", "JPEG", "JPG", "PNG");
for ($i = 0; $i < count($_FILES["file"]["name"]); $i++) {
    $currFileName = $_FILES["file"]["name"][$i];
    $currFileTmpName = $_FILES["file"]["tmp_name"][$i];
    $temp = explode(".", $currFileName);
    $extension = strtoupper(end($temp));
    $currFileType = $_FILES["file"]["type"][$i];
    $currFileError = $_FILES["file"]["error"][$i];
    if (($currFileType == "image/gif" || $currFileType == "image/jpeg" || $currFileType == "image/jpg" || $currFileType == "image/pjpeg" || $currFileType == "image/x-png" || $currFileType == "image/png") && in_array($extension, $allowedExts)) {
        if ($currFileError > 0) {
            // echo "Return Code: " . $currFileError . "<br>";
        } else {
Example #20
0
    $sortorder = $_GET['sortorder'];
    if ($sortorder != '') {
        if ($_GET['filterscount'] == 0) {
            if ($sortorder == "desc") {
                $query = $base_query . " " . $sortfield . " DESC LIMIT {$start}, {$pagesize}";
            } else {
                if ($sortorder == "asc") {
                    $query = $base_query . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                }
            }
        } else {
            if ($sortorder == "desc") {
                $filterquery .= " ORDER BY" . " " . $sortfield . " DESC LIMIT {$start}, {$pagesize}";
            } else {
                if ($sortorder == "asc") {
                    $filterquery .= " ORDER BY" . " " . $sortfield . " ASC LIMIT {$start}, {$pagesize}";
                }
            }
            $query = $filterquery;
        }
    }
}
$result = $mysqli->query($query);
$advisercpd = array();
// get data and store in a json array
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    $advisercpd[] = array('ID' => checkNull($row['ID'], 0), 'CPD_ID' => checkNull($row['CPD_ID'], ''), 'CPD_Name' => checkNull($row['Name'], ''), 'Points' => checkNull($row['Points'], ''), 'Certificate' => checkNull($row['Certificate'], ''), 'Result' => checkNull($row['Result'], ''), 'Date_Taken' => checkNull($row['Date_Taken'], ''));
}
$data[] = array('TotalRows' => $total_rows, 'Rows' => $advisercpd);
echo json_encode($data);
$mysqli->close();
Example #21
0
/**
 * @param $sql
 * @param $table
 * @param $event
 * @param $record
 * @param $display
 * @param string $descrip
 * @param string $change_reason
 * @param $userid
 * @return bool|mysqli_result
 *
 * This function should only be used when required, to impersonate another user for the purpose of ensuring data integrity.
 * One example of this purpose is to replicate Survey respondent input so survey functionality is maintained.
 */
function target_proxy_log_event($sql, $table, $event, $record, $display, $descrip = "", $change_reason = "", $userid = "")
{
	global $user_firstactivity, $rc_connection;

	// Pages that do not have authentication that should have USERID set to [non-user]
	$nonAuthPages = array("_cron/cirrhosis_reporting.php", "_cron/push-hcvrna-monitoring.php", "_cron/push_durations.php", "_cron/push_durations_to_repo.php", "_cron/push_svr_actual_to_pivot.php", "push_svr_actual_to_pivot.php", "_cron/update_daa.php");

	// Log the event in the redcap_log_event table
	$ts = str_replace(array("-", ":", " "), array("", "", ""), NOW);
	$page = (defined("PAGE") ? PAGE : "");
	$ip = (isset($userid) && $userid != "[Survey respondent]") ? "" : getIpAddress(); // Don't log IP for survey respondents
	$event = strtoupper($event);
	$event_id = (isset($_GET['event_id']) && is_numeric($_GET['event_id'])) ? $_GET['event_id'] : "NULL";
	$project_id = defined("PROJECT_ID") ? PROJECT_ID : 0;

	// Query
	$sql = "INSERT INTO redcap_log_event
			(project_id, ts, user, ip, page, event, object_type, sql_log, pk, event_id, data_values, description, change_reason)
			VALUES ($project_id, $ts, '" . prep($userid) . "', " . checkNull($ip) . ", '$page', '$event', '$table', " . checkNull($sql) . ",
			" . checkNull($record) . ", $event_id, " . checkNull($display) . ", " . checkNull($descrip) . ", " . checkNull($change_reason) . ")";
	$q = db_query($sql, $rc_connection);

	// FIRST/LAST ACTIVITY TIMESTAMP: Set timestamp of last activity (and first, if applicable)
	if (defined("USERID") && strpos(USERID, "[") === false) {
		// SET FIRST ACTIVITY TIMESTAMP: If this is the user's first activity to be logged in the log_event table, then log the time in the user_information table
		$sql_firstact = "";
		if ((!isset($user_firstactivity) || (isset($user_firstactivity) && empty($user_firstactivity)))) {
			$sql_firstact = ", user_firstactivity = '" . NOW . "'";
		}
		// SET LAST ACTIVITY TIMESTAMP
		$sql = "update redcap_user_information set user_lastactivity = '" . NOW . "' $sql_firstact
				where username = '******' limit 1";
		db_query($sql, $rc_connection);
	}

	// Return true/false success for logged event
	return $q;
}
        print "\t\t\t</select>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t<td valign='top' style='font-size:11px;color:#666;padding-left:10px;'>\n\t\t\t\t\t\t\t{$lang['calendar_popup_24']} {$table_pk_label}\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr></table>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
    }
    print "<tr>\n\t\t\t\t<td></td>\n\t\t\t\t<td valign='top'>\n\t\t\t\t\t<br><br>\n\t\t\t\t\t<input type='submit' value='{$lang['calendar_popup_25']}' onclick=\"\n\t\t\t\t\t\tif (document.getElementById('notes').value.length < 1) {\n\t\t\t\t\t\t\talert('{$lang['calendar_popup_26']}');\n\t\t\t\t\t\t\treturn false;\t\t\t\t\t\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\">\n\t\t\t\t\t<br><br>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</form>";
    /**
     * DISPLAY CONFIRMATION THAT NEW CALENDAR EVENT WAS CREATED
     */
} elseif (!isset($_GET['cal_id']) && !empty($_POST)) {
    //If an existing record was selected, make sure record doesn't already exist in a DAG. If so, add its group_id to calendar event.
    if ($_POST['idnumber'] != "") {
        $group_id = db_result(db_query("select value from redcap_data where project_id = {$project_id} and record = '{$_POST['idnumber']}' and field_name = '__GROUPID__' limit 1"), 0);
        //If did not select a record, check if user is in DAG.
    } elseif ($user_rights['group_id'] != "") {
        $group_id = $user_rights['group_id'];
    }
    //Add event to calendar
    $sql = "insert into redcap_events_calendar (project_id, group_id, record, event_date, event_time, notes) values " . "({$project_id}, " . checkNull($group_id) . ", " . checkNull($_POST['idnumber']) . ", '{$_POST['event_date']}', " . checkNull($_POST['event_time']) . ", '" . prep($_POST['notes']) . "')";
    //Success
    if (db_query($sql)) {
        //Logging
        log_event($sql, "redcap_events_calendar", "MANAGE", $new_cal_id, calLogChange(db_insert_id()), "Create calendar event");
        //Show confirmation
        print "<div style='color:green;padding:30px 0 0 15px;margin-bottom:10px;font-weight:bold;font-size:16px;'>\n\t\t\t\t\t<img src='" . APP_PATH_IMAGES . "tick.png'>{$lang['calendar_popup_27']}<br><br><br>\n\t\t\t\t</div>";
        //Render javascript to refresh calendar underneath and close pop-up
        print "<script type='text/javascript'>\n\t\t\t\twindow.opener.location.reload();\n\t\t\t\tsetTimeout(function(){self.close();},2500);\n\t\t\t\t</script>";
        //Query failed
    } else {
        print "<p><b>{$lang['global_01']}{$lang['colon']}</b> {$lang['calendar_popup_28']}</p>";
        if (SUPER_USER) {
            print db_error() . "<br>QUERY:<br>{$sql}";
        }
    }
function uploadFinancialIndex($file, $fileMore)
{
    // financial_index_all
    // line 1 : title列 公司代號 公司名稱 季別 ry
    // line 2 start : 公司data列 公司ID 公司名稱 季別 ry
    // 讀取兩個檔案
    // 看哪個col數較多 設為file1 另一個為file2
    $tempFile = loadCsvFile($file);
    $tempFile2 = loadCsvFile($fileMore);
    if ($tempFile && $tempFile2) {
        $tempFileRowArray = fgetcsv($tempFile);
        $tempFile2RowArray = fgetcsv($tempFile2);
        if (count($tempFileRowArray) > count($tempFile2RowArray)) {
            $file1 = $tempFile;
            $file2 = $tempFile2;
        } else {
            $file1 = $tempFile2;
            $file2 = $tempFile;
        }
        $fileRow = fgetcsv($file1);
        $file2Row = fgetcsv($file2);
        // 計算所需col index  data[i]的i x file col數
        // (1, 13) (3, 12) (4, 10) ... (8, 3)
        $colIndexArray = countFinancialIndex($fileRow, 1);
        $colIndexMoreArray = countFinancialIndex($file2Row, 2);
        // for each row
        //    儲存file1資料至data[]
        //    while (file2 company_id < file1 company_id & file2 != null ) , file2 do fgetcsv
        //    if (相同) 將file2中需要的資料儲存在data[]
        //    else (file2 company_id > file1 company_id) 將data[]剩餘欄位設為null
        //    將data[]轉成字串sql
        //    上傳sql
        // loop until file1 無資料
        $dataNum = 0;
        $mysql_command = '';
        while ($file1Row = fgetcsv($file1)) {
            for ($i = 0; $i < count($colIndexArray); $i++) {
                $financialIndexData[$dataNum][$colIndexArray[$i][0]] = $file1Row[$colIndexArray[$i][1]];
            }
            $season = convertDate2Season($financialIndexData[$dataNum][1]);
            // 檢查季別是否與使用者輸入的季別相同
            // 若相同則繼續上傳動作
            if (checkUploadSeason($season)) {
                while ($file2Row = fgetcsv($file2)) {
                    if (trim($file2Row[0]) >= trim($financialIndexData[$dataNum][0])) {
                        break;
                    }
                }
                if (trim($file2Row[0]) === trim($financialIndexData[$dataNum][0])) {
                    for ($i = 0; $i < count($colIndexMoreArray); $i++) {
                        $financialIndexData[$dataNum][$colIndexMoreArray[$i][0]] = $file2Row[$colIndexMoreArray[$i][1]];
                    }
                } else {
                    for ($i = 0; $i < count($colIndexMoreArray); $i++) {
                        $financialIndexData[$dataNum][$colIndexMoreArray[$i][0]] = 'null';
                    }
                }
                $sql = '';
                for ($i = 0; $i < count($financialIndexData[$dataNum]); $i++) {
                    if ($sql != '') {
                        $sql .= ', ';
                    }
                    if ($i === 1) {
                        // season轉換格式
                        $sql .= convertDate2Season($financialIndexData[$dataNum][$i]);
                    } else {
                        $sql .= checkNull($financialIndexData[$dataNum][$i]);
                    }
                }
                if ($mysqlCommand != '') {
                    $mysqlCommand .= ', ';
                }
                $mysqlCommand .= '( ' . $sql . ')';
                $dataNum++;
            } else {
                printError('檔案內的季別與輸入的上傳季別不一致 取消上傳動作');
            }
        }
        $insertValue = '(`company_id`, `season`, `gross_margin`, `operating_income`, `pretax_income`, `ps_sales`, `ps_operating_income`, `ps_pre_tax_income`, `roe`, `roa`, `eps`, `current`, `acid_test`, `liabilities`, `times_interest_earne`, `aoverr_and_noverr_turnover`, `inventory_turnover`, `fixed_asset_turnover`, `total_asset_turnover`, `debt_over_equity_ratio`, `liabilities_to_assets_ratio`, `cashflow_operating`, `cashflow_investment`, `cashflow_financing`, `proceed_fm_newIssue`, `total_equity`, `lt_liabilities`, `total_fixed_assets`, `lt_investment`, `interest_exp`, `total_liabilities`, `net_sales`, `pre_tax_income`, `change_in_cashflow`) VALUES
			' . $mysqlCommand . '<br>';
        $GLOBALS['dbc_object']->insertData('financial_index_all', $insertValue);
    }
}