-
Notifications
You must be signed in to change notification settings - Fork 0
/
InscriptionPetitCoursVC.m
156 lines (121 loc) · 5.26 KB
/
InscriptionPetitCoursVC.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// InscriptionPetitCoursVC.m
// iMines-1
//
// Created by François de la Taste on 12/09/10.
/*
This file is part of iMines ParisTech.
iMines ParisTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
iMines ParisTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#import "InscriptionPetitCoursVC.h"
#import "ASIFormDataRequest.h"
@implementation InscriptionPetitCoursVC
@synthesize nomPC, matierePC, adressePC, niveauPC, commentairePC, selectedPetitCours;
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
- (id)initWithPetitCours:(NSMutableDictionary *)pc {
selectedPetitCours = pc;
NSLog(@"Received PC : %@", [selectedPetitCours objectForKey:@"nom"]);
return [super init];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
nomPC.text = [selectedPetitCours objectForKey:@"nom"];
matierePC.text = [selectedPetitCours objectForKey:@"matiere"];
niveauPC.text = [selectedPetitCours objectForKey:@"niveau"];
commentairePC.text = [selectedPetitCours objectForKey:@"commentaire"];
adressePC.text = [selectedPetitCours objectForKey:@"adresse"];
[super viewDidLoad];
}
- (IBAction)sIncrirePressed {
UIActionSheet *actionSheet = [UIActionSheet alloc];
[actionSheet initWithTitle:@"S'inscrire pour ce petit cours ?" delegate:self cancelButtonTitle:@"Annuler" destructiveButtonTitle:@"Je m'inscris" otherButtonTitles:nil];
//[actionSheet showFromTabBar:self.tabBarController.tabBar];
[actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"button index : %d",buttonIndex);
if(buttonIndex==0){
NSLog(@"je veux m'inscrire !");
// Vérification de l'existence d'une identité :
NSUserDefaults *defaultSettings = [NSUserDefaults standardUserDefaults];
NSString *userLogin = [defaultSettings stringForKey:@"login_ccsi"];
NSLog(@"User : %@", userLogin);
if ([userLogin length]==0) {
NSLog(@"userLogin vide !");
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Erreur :" message:@"Votre login n'est pas renseigné!\nVoir Préférences iMines" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
[errorAlert release];
}
else {
NSLog(@"Formulaire bien rempli");
// Construction email et promo
NSString *email = [userLogin stringByAppendingFormat:@"@ensmp.fr"];
NSString *promo = [userLogin stringByPaddingToLength:2 withString:@"0" startingAtIndex:0];
//NSLog(@"email : %@ // promo : %@", email, promo);
// Construction de la requête
NSURL *urlPC = [[NSURL alloc] initWithString:@"http://www.monbde.eu/petitscours/iMines/InscriptionPC.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:urlPC];
[urlPC release];
[request setPostValue:userLogin forKey:@"nom"];
[request setPostValue:userLogin forKey:@"prenom"];
[request setPostValue:promo forKey:@"annee"];
[request setPostValue:email forKey:@"email"];
[request setPostValue:[selectedPetitCours objectForKey:@"id"] forKey:@"id"];
[request start];
NSError *error = [request error];
if (!error) {
NSLog(@"Pas d'erreur !");
NSString *response = [request responseString];
NSLog(@"Reponse : %@", response);
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Demande enregistrée !" message:@"Merci et à bientôt..." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
[errorAlert release];
[self.navigationController popViewControllerAnimated:YES];
}
else {
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Erreur :" message:@"Impossible d'envoyer la requête" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
[errorAlert release];
}
}
}
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end