input->is_cli_request()) { $cli = true; } else { $this->output->set_status_header(403, 'Jobs must be run from the CLI'); echo "Jobs must be run from the CLI"; exit; } $this->CIS_AMPELVERWALTUNG_URL = CIS_ROOT. "cis/index.php?menu=". CIS_ROOT. "cis/menu.php?content_id=&content=". CIS_ROOT. "cis/private/tools/ampelverwaltung.php"; // Load models $this->load->model('content/Ampel_model', 'AmpelModel'); $this->load->model('person/Person_model', 'PersonModel'); // Load helpers $this->load->helper('hlp_sancho'); } /** * Main function index as help * * @return void */ public function index() { $result = "The following are the available command line interface commands\n\n"; $result .= "php index.ci.php jobs/AmpelMail generateAmpelMail"; echo $result. PHP_EOL; } /** * Generates mail content for new and overdue Ampeln, which * 1. are not confirmed by the user yet and * 2. are marked to be sent by email * Ampel is new when inserted within the last 7 days before the cronjob runs (as cronjob runs weekly) * Ampel is overdue when the cronjob runs after the deadline date. * @return void */ public function generateAmpelMail() { // Get all notifications, that are not expired, not before vorlaufzeit AND email is true $result_active_ampeln = $this->AmpelModel->active(true); // Stores users, description, deadline and system-link of notifications $new_ampel_data_arr = array(); // data of new notifications that are not confirmed $overdue_ampel_data_arr = array(); // data of overdue notifications that are not confirmed if (hasData($result_active_ampeln)) { $ampel_arr = $result_active_ampeln->retval; // Loop through ampeln foreach ($ampel_arr as $ampel) { echo "Checking Ampel: ".$ampel->kurzbz; $ampel_id = $ampel->ampel_id; $now = date_create(date('Y-m-d')); $deadline = date_create($ampel->deadline); $insert_date = date_create($ampel->insertamum); $qry_all_ampel_user = $ampel->benutzer_select; // sql select to get all user who get this ampel $new = false; $overdue = false; // get all user, who get this ampel $result_ampel_user = $this->AmpelModel->execBenutzerSelect($qry_all_ampel_user); if (hasData($result_ampel_user)) { $ampel_user_arr = $result_ampel_user->retval; // loop through all user, who get this ampel foreach ($ampel_user_arr as $ampel_user) { $uid = $ampel_user->uid; // break if ampel was almost confirmed by the user if($this->AmpelModel->isConfirmed($ampel_id, $uid)) continue; // check if ampel is new (inserted within last week, as cronjob will run every week) if ($now->diff($insert_date)->days <= 7) $new = true; //check if ampel is overdue if ($now > $deadline) $overdue = true; // if ampel is new if ($new) { $html_text = '
'. strtoupper($ampel->kurzbz). '
'. strtoupper($ampel->kurzbz). '
Die Deadline für die Bestätigung war am
'. date_format($deadline, 'Y-m-d'). '