Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

+ Added a function to get a random student from a desired class.

  • Loading branch information...
commit 80c2bc278e3597c43b1712d0863d9273d04d835b 1 parent 326bd20
Selman Eser authored
41  library/modules/class/class.source.php
@@ -17,7 +17,7 @@ function class_main()
17 17
 {
18 18
 	global $core;
19 19
 
20  
-	$actions = array('list', 'plus', 'minus', 'edit', 'delete');
  20
+	$actions = array('list', 'plus', 'minus', 'edit', 'random', 'delete');
21 21
 
22 22
 	$core['current_action'] = 'list';
23 23
 	if (!empty($_REQUEST['action']) && in_array($_REQUEST['action'], $actions))
@@ -291,6 +291,45 @@ function class_edit()
291 291
 	$core['current_template'] = 'class_edit';
292 292
 }
293 293
 
  294
+function class_random()
  295
+{
  296
+	global $core, $template;
  297
+
  298
+	$id_class = !empty($_REQUEST['class']) ? (int) $_REQUEST['class'] : 0;
  299
+
  300
+	$request = db_query("
  301
+		SELECT id_class
  302
+		FROM class
  303
+		WHERE id_class = $id_class
  304
+		LIMIT 1");
  305
+	list ($id_class) = db_fetch_row($request);
  306
+	db_free_result($request);
  307
+
  308
+	if (empty($id_class))
  309
+		fatal_error('The class requested does not exist!');
  310
+
  311
+	$request = db_query("
  312
+		SELECT student_name, student_surname
  313
+		FROM student
  314
+		WHERE id_class = $id_class
  315
+		ORDER BY RAND()
  316
+		LIMIT 1");
  317
+	while ($row = db_fetch_assoc($request))
  318
+	{
  319
+		$template['student'] = array(
  320
+			'name' => $row['student_name'],
  321
+			'surname' => $row['student_surname'],
  322
+		);
  323
+	}
  324
+	db_free_result($request);
  325
+
  326
+	if (empty($template['student']))
  327
+		fatal_error('The class requested does not have any students!');
  328
+
  329
+	$template['page_title'] = 'Random Student';
  330
+	$core['current_template'] = 'class_random';
  331
+}
  332
+
294 333
 function class_delete()
295 334
 {
296 335
 	$id_class = !empty($_REQUEST['class']) ? (int) $_REQUEST['class'] : 0;
17  library/modules/class/class.template.php
@@ -48,9 +48,10 @@ function template_class_list()
48 48
 				<tr>
49 49
 					<td>', $class['name'], '</td>
50 50
 					<td>', $class['size'], '</td>
51  
-					<td class="span4 align_center">
  51
+					<td class="span5 align_center">
52 52
 						<a class="btn btn-success" href="', build_url(array('class', 'plus', $class['id'])), '">Add Plus</a>
53 53
 						<a class="btn btn-warning" href="', build_url(array('class', 'minus', $class['id'])), '">Add Minus</a>
  54
+						<a class="btn" href="', build_url(array('class', 'random', $class['id'])), '">Random</a>
54 55
 						<a class="btn btn-info" href="', build_url(array('class', 'edit', $class['id'])), '">Edit</a>
55 56
 						<a class="btn btn-danger" href="', build_url(array('class', 'delete', $class['id'])), '">Delete</a>
56 57
 					</td>
@@ -167,4 +168,18 @@ function template_class_edit()
167 168
 			</fieldset>
168 169
 			<input type="hidden" name="class" value="', $template['class']['id'], '" />
169 170
 		</form>';
  171
+}
  172
+
  173
+function template_class_random()
  174
+{
  175
+	global $template;
  176
+
  177
+	echo '
  178
+		<div class="page-header">
  179
+			<div class="pull-right">
  180
+				<a class="btn" href="', build_url(array('class')), '">Back to List</a>
  181
+			</div>
  182
+			<h2>Random Student</h2>
  183
+		</div>
  184
+		<h3>', $template['student']['name'], ' ', $template['student']['surname'], '</h3>';
170 185
 }

0 notes on commit 80c2bc2

Please sign in to comment.
Something went wrong with that request. Please try again.