<?php header('Content-Type: application/javascript; charset=utf-8'); if (!isset($_GET['p_id'])) { exit; } $p_id = substr($_GET['p_id'], 2); require_once 'send_whatsapp.php'; $conn = new mysqli('localhost', 'moridimt_admin', 'admin@1234', 'moridimt_a-report'); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $conn->query("SET NAMES 'utf8'"); $conn->query("SET CHARACTER SET utf8"); $result = $conn->query('select id, p_id from users where p_id=' . $p_id)->fetch_row(); if ($result != null) { $code = $result[0]; sendWhatsapp($p_id, 'שלום, הקוד שלך לדוח סגולה הוא ' . $code . '. יום טוב.'); $status = [status => true, msg => 'קוד המשתמש נשלח בהצלחה למספר שהזנת']; } else { $status = [status => false, msg => 'המספר שהזנת לא נמצא במערכת. אנא פנה לגורמי המשאן']; } echo $_GET['callback'] . '(' . json_encode($status) . ');';
date_default_timezone_set('Asia/Jerusalem'); $day = Date('Y-m-d'); $file_time = microtime(); $absence_reason = ['לא דווח', 'חופש', 'מחלה', 'חו"ל', 'מחוץ ליחידה', 'קורס', 'מיוחדת', 'מחלה בהצהרה', 'יום ד', 'מחלת ילד', 'חופשת לידה', 'אחר']; $conn->query('update reports set notification="' . $file_time . '" where notification is null'); $items = $conn->query('SELECT notifications.informed_id, users.nickname, reports.status from reports, notifications, users where users.id=notifications.sender_id and users.id=reports.u_id and reports.active=1 and reports.status>0 and notifications.active=1 and (select get_changes from users where p_id=notifications.informed_id)=1 and reports.day="' . $day . '" and reports.notification="' . $file_time . '"'); foreach ($items as $item) { sendWhatsapp($item[informed_id], 'דיווח ' . $absence_reason[$item[status]] . ' הוזן עבור ' . $item[nickname]); } $conn->query('update future_reports set notification="' . $file_time . '" where notification is null'); $items = $conn->query('SELECT notifications.informed_id, users.nickname, future_reports.status, future_reports.start_day, future_reports.end_day from future_reports, notifications, users where users.id=notifications.sender_id and users.id=future_reports.u_id and future_reports.active=1 and notifications.active=1 and (select get_changes from users where p_id=notifications.informed_id)=1 and future_reports.notification="' . $file_time . '"'); foreach ($items as $item) { $date_str = ' עתידי ל- ' . date('j/n', strtotime($item[end_day])); if ($item[start_day] != $item[end_day]) { $date_str .= '-' . date('j/n', strtotime($item[start_day])); } sendWhatsapp($item[informed_id], 'דיווח ' . $absence_reason[$item[status]] . $date_str . ' הוזן עבור ' . $item[nickname]); } $items = $conn->query('SELECT users.p_id, reports.status from users, reports where users.id=reports.u_id and reports.active=1 and reports.status>0 and users.get_approval=1 and day="' . $day . '" and notification="' . $file_time . '"'); foreach ($items as $item) { sendWhatsapp($item[p_id], 'דיווח ' . $absence_reason[$item[status]] . ' הוזן עבורך בהצלחה'); } $items = $conn->query('SELECT users.p_id, future_reports.status, future_reports.start_day, future_reports.end_day from users, future_reports where users.id=future_reports.u_id and future_reports.active=1 and users.get_approval=1 and notification="' . $file_time . '"'); foreach ($items as $item) { $date_str = ' עתידי ל- ' . date('j/n', strtotime($item[end_day])); if ($item[start_day] != $item[end_day]) { $date_str .= '-' . date('j/n', strtotime($item[start_day])); } sendWhatsapp($item[p_id], 'דיווח ' . $absence_reason[$item[status]] . $date_str . ' הוזן עבורך בהצלחה'); } $conn->close();
} $items = $conn->query('SELECT notifications.informed_id, users.nickname FROM notifications, users where users.id=notifications.sender_id and notifications.active=1 and (select get_report from users where p_id=notifications.informed_id)=1 and users.id not in (select u_id from reports where active=1 and day="' . $day . '")'); foreach ($items as $item) { $id = intval($item['informed_id']); if (!array_key_exists($id, $notifications)) { $notifications[$id] = []; } if (!array_key_exists(0, $notifications[$id])) { $notifications[$id][0] = $absence_reason[0] . ' - '; } $notifications[$id][0] .= $item['nickname'] . ', '; } foreach ($notifications as $informed_id => $message_array) { $message = ''; foreach ($message_array as $status => $msg) { $message .= $msg; } sendWhatsapp($informed_id, substr($message, 0, strlen($message) - 2)); } if ($conn->query('select day from locked where day="' . $day . '"')->num_rows == 0) { $conn->query('insert into locked (day) values ("' . $day . '")'); } $sql = 'SELECT users.p_id, reports.status FROM users, reports WHERE reports.active=1 and reports.day="' . $day . '" and users.id=reports.u_id'; $reports = $conn->query($sql); $str = str_replace('-', '', $day); foreach ($reports as $report) { $str .= $report['p_id'] . str_pad($report['status'], 2, '0', STR_PAD_LEFT); } QRcode::png($str); } $conn->close();