} if (!is_readable($listfile)) { throw new Exception("File {$listfile} is not readable"); } $subjectlist = explode("\n", file_get_contents($listfile)); foreach ($subjectlist as &$label) { $label = trim(strtoupper($label)); } try { $config = new \NRG\Configuration("config.ini.php"); $dbconfig = $config->Database; $db = new Database($dbconfig['host'], $dbconfig['user'], $dbconfig['pass'], $dbconfig['name']); if (!$db) { throw new Exception("Couldn't connect to the database."); } $subjects = $db->listSubjects(); $labelsInDB = array(); foreach ($subjects as $subject) { $label = $subject['subjectLabel']; if (in_array($label, $labelsInDB)) { continue; } $labelsInDB[] = trim(strtoupper($label)); } $notInDB = array_diff($subjectlist, $labelsInDB); $notInList = array_diff($labelsInDB, $subjectlist); $countNotInDB = count($notInDB); $countNotInList = count($notInList); if ($countNotInDB) { file_put_contents("not_in_db.csv", implode("\n", $notInDB)); }
switch ($temp) { case 'CSV': $format = $temp; $content_type = 'text/csv'; $content_disposition = "attachment; filename=subjects.csv"; break; } } try { $config = new \NRG\Configuration("../config.ini.php"); $dbconfig = $config->Database; $db = new Database($dbconfig['host'], $dbconfig['user'], $dbconfig['pass'], $dbconfig['name']); if (!$db) { throw new Exception("Couldn't connect to the database."); } $result = $db->listSubjects($field, $direction); if (empty($format)) { ajax_result(array("total" => count($result), "subjects" => $result)); } else { header('Content-type: ' . $content_type); header('Content-disposition: ' . $content_disposition); switch ($format) { case 'CSV': print toCSV($result, array('Label', 'Entries', 'Last Changed', 'Locked'), array('diff')); } } } catch (\Exception $e) { error_log('[OnlineQuestionnaire] ERROR: ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine(), 0); } function toCSV(array $data, array $headers = null, array $ignore = null) {