. */ if( !isset($appl_id) ) { exit(); } include("./include/Appl.php"); include("./include/ApplicationUI.php"); include("./include/ApplicationMail.php"); if( is_before_ex("EventDateAppStart") && !in_array("application_new", $_SESSION['sess_functions']) ) { // Application did not open yet echoln("The application did not open yet, you cannot apply now."); echoln("
The applications will open on ".$setup['EventDateAppStart'].". Please come back from then on, but before the deadline (".$setup['EventDateAppEnd'].")."); }elseif( $setup['ApplicationAdminOpen']==false && !in_array("application_new", $_SESSION['sess_functions']) ) { // Application locked by admin echoln("The application has been locked by the webmaster, as it is not ready to be used yet."); echoln("
Before the application can open, the chair team and the local organizers have to finalize the setup first, please be a bit patient."); }elseif( !is_before("EventDateAppEndReal") && $appl_id==0 && (!isset($_SESSION['sess_functions']) || !in_array("application_new", $_SESSION['sess_functions'])) ) { // Application deadline passed echoln("The application deadline passed, you cannot apply any more."); echoln("
The deadline to apply for this event was on ".$setup['EventDateAppEndReal'].". You cannot apply any more. For next time you are suggested to apply well before the deadline."); }elseif( isset($_SESSION['sess_name']) && stripos($_SESSION['sess_name'], "account" )!==false ) { // Trying to apply with master account echoln("You cannot apply a master account."); echoln("
You cannot apply when logged in with the master account of your local. Please use your personal ".$ldap->getSystemName()." account."); }else { $values = array(); // Load the values from MySQL in case we are editing if( $appl_id>0 ) { $query="SELECT * FROM `persons` WHERE `PersonID`=".addslashes($appl_id); if( @mysql_num_rows( $res=doquery($query) )==1 ) { $values = mysql_fetch_array($res); }else { echoln("Failed loading your application. Editing not possible. Switching back to a new application.

"); $appl_id=0; } } // Load the values in case this is an invitation if( $appl_id==-1 ) { $values = $invite; $appl_id = 0; $invitation = true; }else { $invitation = false; } // Read extra questions $extraQuestions = array(); $query = "SELECT `id`, `question`, `maxlength` FROM `appl_extraquestions` ORDER BY `order`"; if( @mysql_num_rows( $res=doquery($query) )>0 ) { while( $row = mysql_fetch_assoc($res) ) { $extraQuestions[$row['id']] = $row; } } if( $appl_id > 0 ) { $query = "SELECT `question_id`, `answer` FROM `appl_extraanswers` WHERE `appl_id` = " . addslashes($appl_id); if( @mysql_num_rows( $res=doquery($query) )>0 ) { $extraAnswers = array(); while( $row = mysql_fetch_assoc($res) ) { $extraAnswers[$row['question_id']] = $row['answer']; } } } // Read the files from ./include/ApplFields/*.php and add them to $fields; $fields = array(); $sepfields = array(); // All fields including separators if( isset($_REQUEST['edit']) AND $values['Accepted']=="yes" ) $dir = dirname($_SERVER["SCRIPT_FILENAME"])."/include/ApplEditFields/*.php"; else $dir = dirname($_SERVER["SCRIPT_FILENAME"])."/include/ApplFields/*.php"; if( is_dir(dirname($dir)) ) { foreach( glob($dir) as $file ) { if( is_file($file) ) { $field = substr(basename($file, ".php"), 3); if( $field!="Separator" ) { include($file); if( $field == "ExtraQuestion" ) { foreach( array_keys($extraQuestions) as $questionId ) { $fields[] = $field . "_" . $questionId; } }else { $fields[] = $field; } } if( $field == "ExtraQuestion" ) { foreach( array_keys($extraQuestions) as $questionId ) { $sepfields[] = $field . "_" . $questionId; } }else { $sepfields[] = $field; } } } }else { debug(dirname($dir)." does not exist, failed loading application form fields"); } // Create user interface $ui = new ApplicationUI($appl_id); // Create the classes, add a value (from aegee.org account (new) or from MySQL (edit)) $person = array(); $capitalsError = false; for( $i=0; $i 0 || $invitation ) { // Edit - get value from MySQL if( isset($extraAnswers[$questionId]) ) { $person[ $fields[$i] ]->init($extraAnswers[$questionId]); } } }else { $class="Appl".$fields[$i]; $person[ $fields[$i] ] = new $class($appl_id); if( $appl_id>0 OR $invitation ) { // Edit - get value from MySQL if( isset($values[ $fields[$i] ]) ) { $person[ $fields[$i] ]->init($values[ $fields[$i] ]); } }else { // New - get value from aegee.org account when available if( isset($_SESSION[ 'user_'.$fields[$i] ]) ) { $person[ $fields[$i] ]->init($_SESSION[ 'user_'.$fields[$i] ]); if( ($fields[$i]=="FirstName" || $fields[$i]=="LastName" ) && $person[ $fields[$i] ]->get()!=$_SESSION[ 'user_'.$fields[$i] ] ) { $capitalsError = true; } } } } } if( $invitation ) { $person['FirstName']->set_access(APPL::ACCESS_R); $person['LastName']->set_access(APPL::ACCESS_R); $person['BodyCode']->set_access(APPL::ACCESS_R); } if( isset($values['Accepted']) && $values['Accepted']!="yes" AND $values['Accepted']!="pending" AND $values['Accepted']!="confirmed" ) $person['Gym']->set_access(APPL::ACCESS_NO); if( $_SERVER['REQUEST_METHOD']=="POST" ) { // Try to save the form $error = $capitalsError; // Check all fields $usefields = array(); for( $i=0; $iget_access( ($appl_id==0) )==Appl::ACCESS_RW ) { $usefields[] = $fields[$i]; $error += !$person[ $fields[$i] ]->check(); } } if( $appl_id==0 ) { // New application, check for duplicate if( isset($_SESSION['sess_functions']) || (isset($_SESSION['access_user']) && !$_SESSION['access_user']) ) { $query="SELECT `PersonID` FROM `persons` WHERE (`FirstName`='".addslashes($person['FirstName']->get())."' AND `LastName`='".addslashes($person['LastName']->get())."') OR `username`='".addslashes($person['FirstName']->get()." ".$person['LastName']->get())."'"; }else { $query="SELECT `PersonID` FROM `persons` WHERE (`FirstName`='".addslashes($person['FirstName']->get())."' AND `LastName`='".addslashes($person['LastName']->get())."') OR `username`='".addslashes((isset($_SESSION['sess_name'])?$_SESSION['sess_name']:"[unknown]"))."'" . (strlen($person['LastName']->get())>0?" OR `username`='".addslashes($person['FirstName']->get()." ".$person['LastName']->get())."'":""); } if( @mysql_num_rows( doquery($query) )>0 ) { // Duplicate entry $error_duplicate = true; $error += true; }else { $error_duplicate = false; } }else { $error_duplicate = false; } if( $error!=false ) { // Error, show them and reshow form if( abs($error)==1 ) echoln("Your application has not been accepted. The following error was found:"); else echoln("Your application has not been accepted. The following ".abs($error)." errors were found:"); echoln("

"); $_SERVER['REQUEST_METHOD']="GET"; }else { ### Form OK, save it ### $data = array(); $applvalues = array(); if( isset($values['username']) ) { $applvalues['old']['username'] = $values['username']; }else { $applvalues['old'] = array(); } for( $i=0; $iget_sql( ($appl_id==0) )); $applvalues = array_merge_recursive($applvalues, $person[ $fields[$i] ]->get_value( ($appl_id==0) )); } if( $appl_id==0 ) { ### Save new ### $sqlfield = "`username`, "; if( isset($_SESSION['access_user']) && $_SESSION['access_user'] ) { $sqlvalue = "'".addslashes($_SESSION['sess_name'])."', "; }else { $sqlvalue = "'', "; } $sqlfield .= "`Created`, `Modified`, `Log`, "; $sqlvalue .= "'".date("Y-m-d H:i:s")."', '".date("Y-m-d H:i:s")."', '".date("Y-m-d H:i:s").": application created by ".addslashes(isset($_SESSION['sess_name']) ? $_SESSION['sess_name'] : "[anonymous]")."', "; $k = array_keys($data); for( $i=0; $i0 ) { $r .= $kn[$i].", "; } } if( strlen($r)>2 ) $r = substr($r, 0, -2); $query = "UPDATE `persons` SET "; if( strlen($r) ) $query .= "`Modified`='".date("Y-m-d H:i:s")."', `Log`=CONCAT(`Log`,'\n".date("Y-m-d H:i:s").": application edited by ".addslashes($_SESSION['sess_name'])." (".addslashes($r).")'), "; $k = array_keys($data); for( $i=0; $iPlease wait while we process your application... (wait until you see 'ready')

"); flush(); $postSaveResult = true; for( $i=0; $ipost_save($savedApplId); } if( !$postSaveResult ) { echoln("Some actions failed, please open your application and check if everything is correct.
"); } $appl_mail = new ApplicationMail($applvalues['old'], $applvalues['new'], $appl_id==0, $savedApplId); $appl_mail->Send(); echoln("
Your application has been saved successfully."); echoln("

... ready

"); echoln("Your application has been processed. If you want to edit your application, come back to this page and log in with your ".$ldap->getSystemName()." account."); if( is_anon() || (isset($_SESSION['access_user']) && $_SESSION['access_user']) ) echoln("

Back

"); else echoln("

Close window

"); }else { echoln("Failed saving your application."); $_SERVER['REQUEST_METHOD']="GET"; } } }else { if( $capitalsError ) { echoln(""); } } ### Show form ### if( $_SERVER['REQUEST_METHOD']=="GET" ) { // Show the form echoln($ui->Open(true)); for( $i=0; $iSeparator()); }else { if( $person[ $sepfields[$i] ]->get_access( ($appl_id==0) )!=Appl::ACCESS_NO ) { // Show field echoln($ui->Add( $person[ $sepfields[$i] ]->get_print_name(), $person[ $sepfields[$i] ]->get_print_value( $person[ $sepfields[$i] ]->get_access( ($appl_id==0) )!=Appl::ACCESS_RW ), $person[ $sepfields[$i] ]->is_error(), $person[ $sepfields[$i] ]->get_compulsory() )); } } } echoln($ui->Close(true)); } } ?>