<?php
  function cmpUsers($user1, $user2)
  {
    if ( $user1["selected"] && !$user2["selected"] )
      return -1;
    else if ( !$user1["selected"] && $user2["selected"] )
      return 1;
      
    $result = strcoll(mb_strtolower($user1["surname"]), mb_strtolower($user2["surname"])); 
    if ($result != 0)
      return $result;
      
    return strcoll(mb_strtolower($user1["name"]), mb_strtolower($user2["name"]));     
  }

  function cmpCourses($course1, $course2)
  {
    return strcoll(mb_strtolower($course1["name"]), mb_strtolower($course2["name"]));
  }

  function cmpSpecializations($spec1, $spec2)
  {
    if ( $spec1["selected"] && !$spec2["selected"] )
      return -1;
    else if ( !$spec1["selected"] && $spec2["selected"] )
      return 1;
      
    return strcoll(mb_strtolower($spec1["name"]), mb_strtolower($spec2["name"]));
  }
  
	class cAdminApplication extends cApplication
	{
		function GetPageById($pageId)
		{
		  $page = NULL;
      $action = isset( $_GET["action"] ) ? $_GET["action"] : "";
	  	
      if ( $pageId == "student" )
          $page = new cStudentPage($this->smarty, $this->db, $action, $_POST, $_GET);
      else if ( $pageId == "teacher" )
          $page = new cTeacherPage($this->smarty, $this->db, $action, $_POST, $_GET);
      else if ( $pageId == "course" )
          $page = new cCoursePage($this->smarty, $this->db, $action, $_POST, $_GET);
      else if ( $pageId == "import" )
          $page = new cImportPage($this->smarty, $this->db, $action, $_POST, $_GET);
      else if ( $pageId == "backup" )
          $page = new cBackupPage($this->smarty, $this->db, $action, $_POST, $_GET);
      else if ( $pageId == "settings" )
          $page = new cSettingsPage($this->smarty, $this->db, $action, $_POST, $_GET);
      else if ( $pageId == "spec" )
          $page = new cSpecializationPage($this->smarty, $this->db, $action, $_POST, $_GET);
          
      return $page && $page->LoggedAs("admin") ? $page : new cMainPage($this->smarty, $this->db, $action, $_POST, $_GET);
		}		
	}
?>
