. */ include("./include/include.php"); if( !in_array("application_viewgym", $_SESSION['sess_functions']) ) { admin_header(); echoln("You are not authorized to see this page."); admin_footer(); exit(); }elseif( isset($_GET['export']) ) { admin_header(true, true); }else { admin_header(); } if( in_array("application_viewgym", $_SESSION['sess_functions']) ) { if( isset($_GET['export']) ) { $query = "SELECT `PersonID`, `GymPreference`, `BodyCode`, `Sex`, `Nationality` FROM `persons` WHERE (`Accepted`='yes' OR `Accepted`='pending' OR `Accepted`='confirmed') AND `LodgingNeeded`='yes' ORDER BY `PersonID`"; if( @mysql_num_rows( $res=doquery($query) )>0 ) { $data = "#PersonID#;#GymPreference#;#BodyCode#;#Sex#;#Nationality#\n"; while( $row = mysql_fetch_array($res) ) { $data .= EVENTNUMID."-".sprintf("%04d", $row['PersonID']).";".$row['GymPreference'].";".$row['BodyCode'].";".$row['Sex'].";".$row['Nationality']."\n"; } header("Last-Modified: " . gmdate("D, d M Y H:i ") . " GMT"); header('Pragma: no-cache'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header("Content-length: ".strlen($data)); header("Content-disposition: attachment; filename=\"gympreferences.csv\""); header("Content-type: text/comma-separated-values"); header("Content-Transfer-Encoding: 8bit"); header('Pragma: public'); echo $data; }else { echoln("No rows to export found."); } admin_footer(true, true); }else { echoln("

Gym preference export

"); echoln("You can export the gym preferences of the participants that are either accepted, pending or confirmed, so you can apply some algorithm to it to divide people over the different gyms. Click below to download the data."); echoln("

Export gym preferences.

"); echoln("
"); echoln("

Gym preference import

"); echoln("You can import the gym selection afterwards. Input should also be in CSV format, separated by semicolon. First column must be the participant ID, the second column the gym this person is selected for. Rows starting with # are considered comments, "); echoln("and will not be imported. Data fields should not be quoted."); echoln("

"); echoln(" "); echoln(" File: "); echoln("
Note: the file cannot exceed ".get_bytesize(get_bytes(min(pow(2, 24), ini_get("upload_max_filesize"))))."."); echoln("
"); echoln("

"); echoln("
"); if( isset($_GET['import']) && in_array("application_editgym", $_SESSION['sess_functions']) ) { echoln("
"); echoln("

Importing results

"); switch($_FILES['file']['error']) { case UPLOAD_ERR_OK: // There is no error, file uploaded with success if( $fp = fopen($_FILES['file']['tmp_name'], "r") ) { $success = 0; $nooverwrite = 0; $ignored = 0; $failed = 0; while( $data = trim(fgets($fp, 1024)) ) { if( substr($data, 0, 1)=="#" ) { // ignore $ignored++; }else { if( preg_match("/^(([0-9]{3}-)?([0-9]{1,4}));([0-9]+)$/", $data, $matches) ) { #$matches[3]: PersonID #$matches[4]: Gym $query = "UPDATE `persons` SET `Gym`=".addslashes($matches[4]).", `Log`=CONCAT(`Log`,'\n".date("Y-m-d H:i:s").": set gym to ".addslashes($matches[4])." with import by ".addslashes($_SESSION['sess_name'])."') WHERE `PersonID`=".addslashes($matches[3]); if( !isset($_POST['overwrite']) ) $query .= " AND `Gym`=0"; if( doquery($query) ) { if( mysql_affected_rows()==1 ) { // OK $success++; }else { // Nothing updated, gym already set $nooverwrite++; } }else { // Failed $failed++; } }else { echoln("Unable to understand row: ".$data."
"); $failed++; } } } fclose($fp); echoln("

Finished:"); echoln("
- Success: ".$success); echoln("
- Not overwritten: ".$nooverwrite); echoln("
- Ignored (comment line): ".$ignored); echoln("
- Failed: ".$failed."

"); }else { echoln("Failed opening file for reading."); } break; case UPLOAD_ERR_INI_SIZE: // The uploaded file exceeds the upload_max_filesize directive in php.ini. case UPLOAD_ERR_FORM_SIZE: // The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form. echoln("The file you uploaded exceeded the limit of ".get_bytesize(min(pow(2, 24), get_bytes(ini_get("upload_max_filesize"))))."."); break; case UPLOAD_ERR_PARTIAL: // The uploaded file was only partially uploaded. echoln("The file was only partially uploaded. Please try again."); break; case UPLOAD_ERR_NO_FILE: // No file was uploaded. echoln("There was no file uploaded. Please select a file for uploading."); break; case UPLOAD_ERR_NO_TMP_DIR: // Missing a temporary folder. case UPLOAD_ERR_CANT_WRITE: // Failed to write file to disk. default: echoln("An unknown error occurred. Please try again. If this fails, contact the webmaster and report error code ".$_FILES['file']['error']. "while uploading a file."); break; } } admin_footer(); } } ?>